Skip to content

Commit

Permalink
Merge pull request #536 from martin31821/fix/scroll-firefox
Browse files Browse the repository at this point in the history
Unifi scrolling behavior across browsers, fixes #532
  • Loading branch information
Ni55aN authored Jul 17, 2021
2 parents 6bdec4f + 6b7472c commit 8f937d8
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/view/zoom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { listenWindow } from './utils';

interface DeltaWheelEvent { wheelDelta: number }

export class Zoom {

el: HTMLElement;
Expand Down Expand Up @@ -34,11 +32,10 @@ export class Zoom {

wheel(e: WheelEvent) {
e.preventDefault();

const rect = this.el.getBoundingClientRect();
const wheelDelta = (e as unknown as DeltaWheelEvent).wheelDelta;
const delta = (wheelDelta ? wheelDelta / 120 : - e.deltaY / 3) * this.intensity;

const rect = this.el.getBoundingClientRect();
const isNegative = e.deltaY < 0;
const delta = isNegative ? this.intensity : - this.intensity;
const ox = (rect.left - e.clientX) * delta;
const oy = (rect.top - e.clientY) * delta;

Expand Down Expand Up @@ -73,7 +70,7 @@ export class Zoom {

if (this.previous !== null) {
let delta = distance / this.previous.distance - 1;

const ox = (rect.left - cx) * delta;
const oy = (rect.top - cy) * delta;

Expand All @@ -89,13 +86,13 @@ export class Zoom {

dblclick(e: MouseEvent) {
e.preventDefault();

const rect = this.el.getBoundingClientRect();
const delta = 4 * this.intensity;

const ox = (rect.left - e.clientX) * delta;
const oy = (rect.top - e.clientY) * delta;

this.onzoom(delta, ox, oy, 'dblclick');
this.onzoom(delta, ox, oy, 'dblclick');
}
}
}

0 comments on commit 8f937d8

Please sign in to comment.