Last active
October 28, 2022 20:24
-
-
Save shlomohass/22249c0da0f53157dfe9 to your computer and use it in GitHub Desktop.
jQuery - Get mousewheel scroll event to detect scrolling direction cross browser
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
$('body').on('mousewheel DOMMouseScroll', function(e){ | |
if(typeof e.originalEvent.detail == 'number' && e.originalEvent.detail !== 0) { | |
if(e.originalEvent.detail > 0) { | |
console.log('Down'); | |
} else if(e.originalEvent.detail < 0){ | |
console.log('Up'); | |
} | |
} else if (typeof e.originalEvent.wheelDelta == 'number') { | |
if(e.originalEvent.wheelDelta < 0) { | |
console.log('Down'); | |
} else if(e.originalEvent.wheelDelta > 0) { | |
console.log('Up'); | |
} | |
} | |
}); |
My hero!
Bro, huge thank you
That's very helpful but it's taking too much time to scroll down or up on mouse wheel event.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Waoh, I was looking for something like that for a looooooong time, my goal was to disable the scroll on a specific div while still being able to navigate throught a slider with the mousewheel.
Thanks a lot !