Skip to content

Instantly share code, notes, and snippets.

@wiledal
Created March 6, 2014 15:57
Show Gist options
  • Save wiledal/9392815 to your computer and use it in GitHub Desktop.
Save wiledal/9392815 to your computer and use it in GitHub Desktop.
Normalize scroll
// Provide "originalEvent" of DOMMouseScroll and mousewheel
var o = event;
var d = o.detail;
var w = o.wheelDelta || o.deltaY;
var n = 225;
var n1 = n - 1;
var d = (d ? (w && (f = w / d) ? d / f : -d / 1.35) : w / 120);
var d = (d < 1 ? (d < -1 ? (-Math.pow(d, 2) - n1) / n : d) : (Math.pow(d, 2) + n1) / n);
event.delta = Math.min(Math.max(d / 2, -1), 1);
return event;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment