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)) {