From aa7e6646acbb0ea52bf5a7041fec8e103f8dfab5 Mon Sep 17 00:00:00 2001 From: Tyler-Maclachlan <32850000+Tyler-Maclachlan@users.noreply.github.com> Date: Fri, 8 Nov 2019 20:49:53 +0200 Subject: [PATCH] fix(events): use the standard wheel event (#208) This event is now supported by all the browsers we care about. There's no need anymore to listen to the legacy events. --- lib/network/modules/Canvas.js | 3 +-- lib/network/modules/InteractionHandler.js | 19 ++----------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/network/modules/Canvas.js b/lib/network/modules/Canvas.js index d8f8c8cad0..c926edc93d 100644 --- a/lib/network/modules/Canvas.js +++ b/lib/network/modules/Canvas.js @@ -249,8 +249,7 @@ class Canvas { this.hammer.on('pinch', (event) => {this.body.eventListeners.onPinch(event)}); // TODO: neatly cleanup these handlers when re-creating the Canvas, IF these are done with hammer, event.stopPropagation will not work? - this.frame.canvas.addEventListener('mousewheel', (event) => {this.body.eventListeners.onMouseWheel(event)}); - this.frame.canvas.addEventListener('DOMMouseScroll', (event) => {this.body.eventListeners.onMouseWheel(event)}); + this.frame.canvas.addEventListener('wheel', (event) => {this.body.eventListeners.onMouseWheel(event)}); this.frame.canvas.addEventListener('mousemove', (event) => {this.body.eventListeners.onMouseMove(event)}); this.frame.canvas.addEventListener('contextmenu', (event) => {this.body.eventListeners.onContext(event)}); diff --git a/lib/network/modules/InteractionHandler.js b/lib/network/modules/InteractionHandler.js index 2a744d4c55..ab82d7bed0 100644 --- a/lib/network/modules/InteractionHandler.js +++ b/lib/network/modules/InteractionHandler.js @@ -503,29 +503,14 @@ class InteractionHandler { */ onMouseWheel(event) { if (this.options.zoomView === true) { - // retrieve delta - let delta = 0; - if (event.wheelDelta) { /* IE/Opera. */ - delta = event.wheelDelta / 120; - } - else if (event.detail) { /* Mozilla case. */ - // In Mozilla, sign of delta is different than in IE. - // Also, delta is multiple of 3. - delta = -event.detail / 3; - } - // If delta is nonzero, handle it. // Basically, delta is now positive if wheel was scrolled up, // and negative, if wheel was scrolled down. - if (delta !== 0) { + if (event.deltaY !== 0) { // calculate the new scale let scale = this.body.view.scale; - let zoom = delta * (this.options.zoomSpeed / 10); - if (delta < 0) { - zoom = zoom / (1 - zoom); - } - scale *= (1 + zoom); + scale *= 1 + (event.deltaY < 0 ? 1 : -1) * (this.options.zoomSpeed * 0.1); // calculate the pointer location let pointer = this.getPointer({x: event.clientX, y: event.clientY});