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 slow scrolling on firefox and on windows with 'one screen at a time' #68

Merged
merged 1 commit into from
Apr 23, 2020
Merged
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
28 changes: 27 additions & 1 deletion src/svg.panzoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ extend(Svg, {
const panButton = options.panButton ?? 0
const oneFingerPan = options.oneFingerPan ?? false
const margins = options.margins ?? false
const wheelZoomdeltaModeLinePixels = options.deltaModeLinePixels ?? 17
const wheelZoomdeltaModeScreenPixels = options.deltaModeScreenPixels ?? 53

let lastP
let lastTouches
Expand Down Expand Up @@ -48,7 +50,31 @@ extend(Svg, {
// touchpads can give ev.deltaY == 0, which skrews the lvl calculation
if (ev.deltaY === 0) return

let lvl = Math.pow(1 + zoomFactor, (-1 * ev.deltaY) / 100) * this.zoom()
// When wheeling on a mouse,
// - chrome by default uses deltaY = 53, deltaMode = 0 (pixel)
// - firefox by default uses deltaY = 3, deltaMode = 1 (line)
// - chrome and firefox on windows after configuring "One screen at a time"
// use deltaY = 1, deltaMode = 2 (screen)
//
// Note that when when wheeling on a touchpad, deltaY depends on how fast
// you swipe, but the deltaMode is still different between the browsers.
//
// Normalize everything so that zooming speed is approximately the same in all cases
let normalizedPixelDeltaY
switch (ev.deltaMode) {
case 1:
normalizedPixelDeltaY = ev.deltaY * wheelZoomdeltaModeLinePixels
break
case 2:
normalizedPixelDeltaY = ev.deltaY * wheelZoomdeltaModeScreenPixels
break
default:
// 0 (already pixels) or new mode (avoid crashing)
normalizedPixelDeltaY = ev.deltaY
break
}

let lvl = Math.pow(1 + zoomFactor, (-1 * normalizedPixelDeltaY) / 100) * this.zoom()
const p = this.point(ev.clientX, ev.clientY)

if (lvl > zoomMax) {
Expand Down