From e8c2860c7d46990d0f848dbf236aa7c998e5952d Mon Sep 17 00:00:00 2001 From: Konv Suu <2583695112@qq.com> Date: Sat, 29 Jul 2023 11:18:22 +0800 Subject: [PATCH] fix(image): sensitivity of image scaling (#6784) --- components/vc-image/src/Preview.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/components/vc-image/src/Preview.tsx b/components/vc-image/src/Preview.tsx index 1bab98b65..fc14f23ea 100644 --- a/components/vc-image/src/Preview.tsx +++ b/components/vc-image/src/Preview.tsx @@ -103,13 +103,22 @@ const Preview = defineComponent({ emit('afterClose'); }; - const onZoomIn = () => { - scale.value++; + const onZoomIn = (isWheel?: boolean) => { + if (!isWheel) { + scale.value++; + } else { + scale.value += 0.5; + } + setPosition(initialPosition); }; - const onZoomOut = () => { + const onZoomOut = (isWheel?: boolean) => { if (scale.value > 1) { - scale.value--; + if (!isWheel) { + scale.value--; + } else { + scale.value -= 0.5; + } } setPosition(initialPosition); }; @@ -152,12 +161,12 @@ const Preview = defineComponent({ }, { icon: zoomIn, - onClick: onZoomIn, + onClick: () => onZoomIn(), type: 'zoomIn', }, { icon: zoomOut, - onClick: onZoomOut, + onClick: () => onZoomOut(), type: 'zoomOut', disabled: computed(() => scale.value === 1), }, @@ -299,9 +308,9 @@ const Preview = defineComponent({ watch([lastWheelZoomDirection], () => { const { wheelDirection } = lastWheelZoomDirection.value; if (wheelDirection > 0) { - onZoomOut(); + onZoomOut(true); } else if (wheelDirection < 0) { - onZoomIn(); + onZoomIn(true); } }); });