Solomko2
8/17/2016 - 5:54 PM

Showing the use of JavaScript code to track mouse wheel events on a specific object on the page, in a manner that normalizes across browsers

Showing the use of JavaScript code to track mouse wheel events on a specific object on the page, in a manner that normalizes across browsers the distance and direction that the wheel has travelled.

//http://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers
var wheelDistance = function(evt){
  if (!evt) evt = event;
  var w=evt.wheelDelta, d=evt.detail;
  if (d){
    if (w) return w/d/40*d>0?1:-1; // Opera
    else return -d/3;              // Firefox;         TODO: do not /3 for OS X
  } else return w/120;             // IE/Safari/Chrome TODO: /3 for Chrome OS X
};

var wheelDirection = function(evt){
  if (!evt) evt = event;
  return (evt.detail<0) ? 1 : (evt.wheelDelta>0) ? 1 : -1;
};