Created
January 10, 2013 22:34
-
-
Save yoannmoinet/4506416 to your computer and use it in GitHub Desktop.
Cross browser scroll event handler, with a consistant delta.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel"; | |
if (document.attachEvent) | |
document.attachEvent("on"+mousewheelevt, function(e){scroller(e)}); | |
else if (document.addEventListener) | |
document.addEventListener(mousewheelevt, function(e){scroller(e)},false); | |
function scroller(evt) | |
{ | |
//Guess the delta. | |
var delta = 0; | |
if (!evt) evt = window.event; | |
if (evt.wheelDelta) { | |
delta = evt.wheelDelta/120; | |
} else if (evt.detail) { | |
delta = -evt.detail/3; | |
} | |
if (evt.preventDefault) evt.preventDefault(); | |
evt.returnValue = false; | |
//Do the magic. | |
//callback(delta); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment