vue-konva实现拖拽和放大缩小
参考konva官网<template><v-stage ref="stage" :config="stageConfig" @wheel="wheelForScale($event)"><v-layer ref="layer"><v-image :config="{image: image}"/></v-layer></v-stag
·
参考konva官网
<template>
<v-stage ref="stage" :config="stageConfig" @wheel="wheelForScale($event)">
<v-layer ref="layer">
<v-image :config="{
image: image
}"/>
</v-layer>
</v-stage>
</template>
<script>
const width = window.innerWidth;
const height = window.innerHeight;
export default {
data() {
return {
stageConfig: {
width: width,
height: height,
// 拖拽
draggable: true
},
image: null
};
},
created() {
const image = new window.Image();
image.src = "https://konvajs.org/assets/yoda.jpg";
image.onload = () => {
// set image only when it is loaded
this.image = image;
};
},
methods: {
// 放大缩小
wheelForScale(e) {
//document.getElementById('ele').addEventListener('mousewheel', function (e) {
// e.preventDefault();
//}, { passive: false });
if (e.evt.wheelDelta > 0) {
let i = 1
this.stageConfig.width += i * 100
i++
}else {
let i = 1
this.stageConfig.width += i * -100
i++
}
}
}
};
</script>
更多推荐
已为社区贡献1条内容
所有评论(0)