Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(move): fix jitter when zooming and panning as described in #651 #652

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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