当前位置: 首页 > news >正文

konva不透明度,查找,显示,隐藏

效果:

代码:

<template><div class="rect"><div class="header"><el-button type="primary" @click="show">展示</el-button><el-button type="success" @click="hide">隐藏</el-button></div><div id="canvas"></div></div>
</template>
<script setup lang="ts">
import {onMounted} from 'vue'
import Konva from 'konva'let  stage:Konva.Stage | null=null
const layer:Konva.Layer=new Konva.Layer()onMounted(()=>{init()
})
const init=()=> {const el = document.getElementById("canvas")if (!el) {return}const { clientWidth, clientHeight } = el//创建一个stage平台stage = new Konva.Stage({container: 'canvas',width: clientWidth,height: clientHeight,})stage.add(layer)//矩形const width =400const height=200const x=clientWidth/2-width/2const y=clientHeight/2-height/2const rect=new Konva.Rect({//给图形添加id和名称,方便之后通过id和名称查找图形id:"textId",name:"textName",x:x,y:y,width:width,height:height,fill:'#ff8800',stroke:'black',strokeWidth:1,opacity:0.5})
layer.add(rect)
}
const show=()=>{if (!stage){return}
//  const shapes=stage.findOne("#textId")//通过id查找// const shapes=stage?.findOne(".textName")//通过名称const shapes=stage?.findOne("Rect")//通过图形的类别来查找console.log(shapes)//设置展示shapes.show()}
const hide=()=>{if (!stage){return}
//  const shapes=stage.findOne("#textId")//通过id查找// const shapes=stage?.findOne(".textName")//通过名称const shapes=stage?.findOne("Rect")//通过图形的类别来查找console.log(shapes)//设置展示shapes.hide()}
</script><style scoped lang="scss">
.rect {padding: 20px;.header{height: 50px;}#canvas {background-color: #eee;border: 1px solid #666;height: calc(100vh - 92px);}
}
</style>

 


http://www.mrgr.cn/news/57155.html

相关文章:

  • hdfs的客户端(big data tools插件)
  • LeetCode-3185 构成整天的下标对数目Ⅱ
  • Docker 安装使用
  • JSON日志处理 | 基于SparkSql实现
  • Vue学习记录之十九 Event Loop,宏任务和微任务
  • ubuntu 24.04 下载安装离线包,ubuntu 24.04 配置xrdp
  • vTESTstudio系列14--vTESTstudio中自定义函数介绍1
  • RHCE时间服务器
  • Vscode + EIDE +CortexDebug 调试Stm32(记录)
  • Kamailio 网络拓扑案例分享
  • C++ set和map的模拟实现
  • Llama Tutor:开源 AI 个性化学习平台,根据主题自动制定学习计划
  • RTDETR 引入 MogaBlock | 多阶门控聚合网络 | ICLR 2024
  • ThinkPad中键打开网页关闭网页失灵
  • 【Linux】线程互斥与同步,生产消费模型(超详解)
  • Redis-05 Redis发布订阅
  • 得物App3D博物馆亮相“两博会”,正品保障助力消费体验升级
  • 10.23Python_matplotlib_乱码问题
  • 三菱FX5U PLC程序容量设置
  • vue3-06-html2canvas使用 + zoom、transform: scale图片缩放适配方案 + 动态引入静态资源(打包上线后也能使用)
  • Java面试题九
  • C语言_动态内存管理
  • 2024年软件设计师中级(软考中级)详细笔记【10】网络与信息安全基础知识(分值5分)
  • 解决RabbitMQ脑裂问题
  • ARM/Linux嵌入式面经(四九):诺瓦星云
  • 特种设备作业G1工业锅炉司炉题库