From 6fc6391d068ccd21838066aca0ed36356a7ee7c0 Mon Sep 17 00:00:00 2001 From: Xin Date: Thu, 11 Sep 2025 23:30:38 +0100 Subject: [PATCH] fix(image-zoom): disable dragging during single touch interactions - Updated logic to prevent dragging when a single touch is detected, improving tap detection accuracy. - Adjusted event handling to ensure significant movement cancels tap only when necessary, enhancing user experience. --- assets/js/image-zoom.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/assets/js/image-zoom.js b/assets/js/image-zoom.js index 77ceb62..7ade9d7 100644 --- a/assets/js/image-zoom.js +++ b/assets/js/image-zoom.js @@ -99,8 +99,7 @@ }); if (pointers.size === 1) { - // Single touch - start drag - isDragging = true; + isDragging = false; setInteracting(true); gestureState.lastPanX = gestureState.panX; gestureState.lastPanY = gestureState.panY; @@ -166,21 +165,12 @@ // Any multi-touch movement cancels tap tapCandidate = false; applyTransform(); - } else if (isDragging && pointers.size === 1) { - // Handle drag/pan - const deltaX = pointer.x - pointer.startX; - const deltaY = pointer.y - pointer.startY; - - gestureState.panX = gestureState.lastPanX + deltaX; - gestureState.panY = gestureState.lastPanY + deltaY; - - // Significant movement cancels tap + } else if (pointers.size === 1) { + // Single pointer: no drag; only cancel tap if large move const moveThreshold = 10; if (Math.abs(pointer.x - tapStartX) > moveThreshold || Math.abs(pointer.y - tapStartY) > moveThreshold) { tapCandidate = false; } - - applyTransform(); } } @@ -204,9 +194,9 @@ }, 300); } } else if (pointers.size === 1) { - // Going from pinch to single touch + // Going from pinch to single touch — keep dragging disabled isPinching = false; - isDragging = true; + isDragging = false; const remaining = Array.from(pointers.values())[0]; gestureState.lastPanX = gestureState.panX; gestureState.lastPanY = gestureState.panY;