page: 📄 设置最大限度拖拽
This commit is contained in:
parent
f4d93e2afe
commit
10ed9a8701
|
@ -1,6 +1,4 @@
|
|||
```sh
|
||||
transform events
|
||||
resize limits
|
||||
rotation snaps
|
||||
resize snaps
|
||||
stop transform
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<script setup lang="ts">
|
||||
import { useWindowSize } from '@vueuse/core';
|
||||
import { onMounted } from 'vue';
|
||||
import Konva from 'konva/lib';
|
||||
|
||||
const { width, height } = useWindowSize();
|
||||
const MAX_WIDTH = 200;
|
||||
|
||||
const initial = () => {
|
||||
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
|
||||
const layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
const rect = new Konva.Rect({
|
||||
x: 160,
|
||||
y: 60,
|
||||
width: 100,
|
||||
height: 90,
|
||||
fill: 'red',
|
||||
name: 'rect',
|
||||
stroke: 'black',
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
|
||||
const tr = new Konva.Transformer({
|
||||
boundBoxFunc: function (oldBoundBox, newBoundBox) {
|
||||
if (Math.abs(newBoundBox.width) > MAX_WIDTH) {
|
||||
return oldBoundBox;
|
||||
}
|
||||
|
||||
return newBoundBox;
|
||||
},
|
||||
});
|
||||
layer.add(tr);
|
||||
tr.nodes([rect]);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
initial();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div id="container"></div>
|
||||
</template>
|
Loading…
Reference in New Issue