Skip to content

Instantly share code, notes, and snippets.

@briangonzalez
Last active October 2, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briangonzalez/2172654 to your computer and use it in GitHub Desktop.
Save briangonzalez/2172654 to your computer and use it in GitHub Desktop.
Bulletproof mouse-wheel event handling
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