page: 📄 自定义样式

This commit is contained in:
bunny 2024-07-12 16:58:28 +08:00
parent 3346703796
commit 9270bb0f4a
2 changed files with 53 additions and 2 deletions

View File

@ -1,6 +1,4 @@
```sh
styling
complex styling
transform events
resize limits
rotation snaps

View File

@ -0,0 +1,53 @@
<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import Konva from 'konva/lib';
const { width, height } = useWindowSize();
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
const circle = new Konva.Circle({
x: 150,
y: 150,
radius: 70,
fill: 'red',
draggable: true,
});
layer.add(circle);
const tr = new Konva.Transformer({
anchorStyleFunc(anchor) {
anchor.cornerRadius(10);
if (anchor.hasName('top-center') || anchor.hasName('bottom-center')) {
anchor.height(8);
anchor.offsetY(3);
anchor.width(30);
anchor.offsetX(15);
}
if (anchor.hasName('middle-left') || anchor.hasName('middle-right')) {
anchor.height(30);
anchor.offsetY(15);
anchor.width(6);
anchor.offsetX(3);
}
},
nodes: [circle],
});
layer.add(tr);
};
onMounted(() => {
initial();
});
</script>
<template>
<div id="container"></div>
</template>
<style scoped lang="scss"></style>