Last active
October 2, 2015 04:28
-
-
Save briangonzalez/2172654 to your computer and use it in GitHub Desktop.
Bulletproof mouse-wheel event handling
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
if ( event.hasOwnProperty('type') && event.type == 'DOMMouseScroll' ){ | |
// Zoom from mousewheel (Firefox) | |
} | |
else if ( event.type == 'mousewheel' && event.originalEvent.hasOwnProperty('wheelDeltaY') ) { | |
// ... (Chrome) | |
} | |
else if ( event.type == 'mousewheel' && event.originalEvent.hasOwnProperty('wheelDelta') ) { | |
// ... (Opera) | |
direction = ( event.originalEvent.wheelDelta > 0 ) ? 'up' : 'down' | |
} | |
else if ( event.originalEvent.hasOwnProperty('scale') ) { | |
// ... (pinch) | |
} | |
else { | |
// Ghetto browser. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment