From 1e20409e04db016ee951fd6fb1c9ca0cc7d4f8fa Mon Sep 17 00:00:00 2001 From: Anthony Marmont Date: Mon, 14 Aug 2023 13:01:55 +0100 Subject: [PATCH] fix(move): fix jitter when zooming and panning as described in #651 --- src/panzoom.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/panzoom.ts b/src/panzoom.ts index 51722106..41dbbb5a 100644 --- a/src/panzoom.ts +++ b/src/panzoom.ts @@ -135,6 +135,14 @@ function Panzoom( let y = 0 let scale = 1 let isPanning = false + let origX: number + let origY: number + let startClientX: number + let startClientY: number + let startScale: number + let startDistance: number + const pointers: PointerEvent[] = [] + zoom(options.startScale, { animate: false, force: true }) // Wait for scale to update // for accurate dimensions @@ -318,6 +326,12 @@ function Panzoom( let toX = x let toY = y + // Adjust the pointer starting point to ensure that the current pointer panning is accurate. + if (isPanning) { + startClientX = (startClientX / scale) * toScale; + startClientY = (startClientY / scale) * toScale; + } + if (opts.focal) { // The difference between the point after the scale and the point before the scale // plus the current translation after the scale @@ -430,14 +444,6 @@ function Panzoom( return setTransformWithEvent('panzoomreset', opts) } - let origX: number - let origY: number - let startClientX: number - let startClientY: number - let startScale: number - let startDistance: number - const pointers: PointerEvent[] = [] - function handleDown(event: PointerEvent) { // Don't handle this event if the target is excluded if (isExcluded(event.target as Element, options)) {