diff --git a/public/verify.json b/public/verify.json index 0eb51f4..a2fb294 100644 --- a/public/verify.json +++ b/public/verify.json @@ -1 +1 @@ -{"version":1721867671704} \ No newline at end of file +{"version":1721883990967} \ No newline at end of file diff --git a/src/views/select/basic/index.vue b/src/views/select/basic/index.vue index ea71342..6fd6ff2 100644 --- a/src/views/select/basic/index.vue +++ b/src/views/select/basic/index.vue @@ -9,7 +9,6 @@ import { Stage } from 'konva/lib/Stage'; import { Layer } from 'konva/lib/Layer'; const { width, height } = useWindowSize(); -// let stage, layer; const stage = ref(); const layer = ref(); @@ -18,13 +17,17 @@ const SCALE_BY = 1.1; const zoomed = () => { stage.value?.on('wheel', ev => { + // 平台不存在直接返回 if (!stage.value) return; // 之前缩放比例 const scaleX = stage.value?.scaleX(); const scaleY = stage.value?.scaleY(); + // 记录当前鼠标位置 const pointer = stage.value?.getPointerPosition(); + + // 鼠标在画布的平移量,除以缩放比例得到,鼠标在未缩放时的坐标 const mousePointTo = { x: (pointer!.x - stage.value?.x()) / scaleX, y: (pointer!.y - stage.value?.y()) / scaleY, @@ -33,10 +36,12 @@ const zoomed = () => { // 判断鼠标滚轮向上还是向下 const direction = ev.evt.deltaY > 0 ? -1 : 1; + // 设置新的缩放比例 const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY; const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY; stage.value?.scale({ x, y }); + // 设置新的鼠标位置,缩放时保持不变 const position = { x: pointer!.x - mousePointTo.x * x, y: pointer!.y - mousePointTo.y * y, diff --git a/src/views/select/keep-ratio/index.vue b/src/views/select/keep-ratio/index.vue index ab147f0..4720e27 100644 --- a/src/views/select/keep-ratio/index.vue +++ b/src/views/select/keep-ratio/index.vue @@ -1,14 +1,51 @@ -