page: 📄 stroke+鼠标事件
This commit is contained in:
parent
efdd6c23c9
commit
7253d71880
|
@ -0,0 +1,47 @@
|
||||||
|
<template><div id="container"></div></template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useWindowSize } from '@vueuse/core';
|
||||||
|
import Konva from 'konva/lib';
|
||||||
|
import { onMounted } from 'vue';
|
||||||
|
|
||||||
|
const { width, height } = useWindowSize();
|
||||||
|
|
||||||
|
const initial = () => {
|
||||||
|
const stage = new Konva.Stage({
|
||||||
|
container: 'container',
|
||||||
|
width: width.value,
|
||||||
|
height: height.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
const layer = new Konva.Layer({ draggable: true });
|
||||||
|
|
||||||
|
const pentagon = new Konva.RegularPolygon({
|
||||||
|
x: stage.width() / 2,
|
||||||
|
y: stage.height() / 2,
|
||||||
|
sides: 5,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'red',
|
||||||
|
stroke: '#000',
|
||||||
|
strokeWidth: 4,
|
||||||
|
draggable: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
pentagon.on('mouseover', function () {
|
||||||
|
this.stroke('blue');
|
||||||
|
this.strokeWidth(20);
|
||||||
|
});
|
||||||
|
|
||||||
|
pentagon.on('mouseout', function () {
|
||||||
|
this.stroke('black');
|
||||||
|
this.strokeWidth(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(pentagon);
|
||||||
|
stage.add(layer);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
initial();
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Reference in New Issue