Browse Source

Normalize mouse wheel deltas (#3911)

* Normalize mouse wheel deltas for #3792

* include support for IE6/7/8
develop
Lukas Bin 6 years ago
committed by Yotam Berkowitz
parent
commit
8441fedecd
1 changed files with 21 additions and 4 deletions
  1. +21
    -4
      lib/timeline/Core.js

+ 21
- 4
lib/timeline/Core.js View File

@ -176,6 +176,11 @@ Core.prototype._create = function (container) {
* @param {WheelEvent} event
*/
function onMouseWheel(event) {
// Reasonable default wheel deltas
const LINE_HEIGHT = 40;
const PAGE_HEIGHT = 800;
if (this.isActive()) {
this.emit('mousewheel', event);
}
@ -204,6 +209,17 @@ Core.prototype._create = function (container) {
deltaX = event.deltaX;
}
// Normalize deltas
if (event.deltaMode) {
if (event.deltaMode === 1) { // delta in LINE units
deltaX *= LINE_HEIGHT;
deltaY *= LINE_HEIGHT;
} else { // delta in PAGE units
deltaX *= LINE_HEIGHT;
deltaY *= PAGE_HEIGHT;
}
}
// Prevent scrolling when zooming (no zoom key, or pressing zoom key)
if (!this.options.zoomKey || event[this.options.zoomKey]) return;
@ -241,11 +257,12 @@ Core.prototype._create = function (container) {
}
}
// Add modern wheel event listener
if (this.dom.centerContainer.addEventListener) {
// IE9, Chrome, Safari, Opera
this.dom.centerContainer.addEventListener("mousewheel", onMouseWheel.bind(this), false);
// Firefox
this.dom.centerContainer.addEventListener("DOMMouseScroll", onMouseWheel.bind(this), false);
const wheel = "onwheel" in document.createElement("div") ? "wheel" : // Modern browsers support "wheel"
document.onmousewheel !== undefined ? "mousewheel" : // Webkit and IE support at least "mousewheel"
"DOMMouseScroll"; // Older Firefox versions like "DOMMouseScroll"
this.dom.centerContainer.addEventListener(wheel, onMouseWheel.bind(this), false);
} else {
// IE 6/7/8
this.dom.centerContainer.attachEvent("onmousewheel", onMouseWheel.bind(this));

Loading…
Cancel
Save