Skip to content

Commit

Permalink
fix(move): fix jitter when zooming and panning as described in timmyw…
Browse files Browse the repository at this point in the history
  • Loading branch information
Fydar committed Aug 14, 2023
1 parent 7428761 commit 1e20409
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/panzoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 1e20409

Please sign in to comment.