Skip to content

Commit 1e20409

Browse files
committed
fix(move): fix jitter when zooming and panning as described in timmywil#651
1 parent 7428761 commit 1e20409

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/panzoom.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ function Panzoom(
135135
let y = 0
136136
let scale = 1
137137
let isPanning = false
138+
let origX: number
139+
let origY: number
140+
let startClientX: number
141+
let startClientY: number
142+
let startScale: number
143+
let startDistance: number
144+
const pointers: PointerEvent[] = []
145+
138146
zoom(options.startScale, { animate: false, force: true })
139147
// Wait for scale to update
140148
// for accurate dimensions
@@ -318,6 +326,12 @@ function Panzoom(
318326
let toX = x
319327
let toY = y
320328

329+
// Adjust the pointer starting point to ensure that the current pointer panning is accurate.
330+
if (isPanning) {
331+
startClientX = (startClientX / scale) * toScale;
332+
startClientY = (startClientY / scale) * toScale;
333+
}
334+
321335
if (opts.focal) {
322336
// The difference between the point after the scale and the point before the scale
323337
// plus the current translation after the scale
@@ -430,14 +444,6 @@ function Panzoom(
430444
return setTransformWithEvent('panzoomreset', opts)
431445
}
432446

433-
let origX: number
434-
let origY: number
435-
let startClientX: number
436-
let startClientY: number
437-
let startScale: number
438-
let startDistance: number
439-
const pointers: PointerEvent[] = []
440-
441447
function handleDown(event: PointerEvent) {
442448
// Don't handle this event if the target is excluded
443449
if (isExcluded(event.target as Element, options)) {

0 commit comments

Comments
 (0)