Created
August 17, 2016 17:54
-
-
Save Solomko2/e41b3e13aed93edec7ca4db46df631ae to your computer and use it in GitHub Desktop.
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.
This file contains hidden or 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
| //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; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment