Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery - Get mousewheel scroll event to detect scrolling direction cross browser
$('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');
}
}
});
@atereshhuk
Copy link

atereshhuk commented Dec 27, 2018

Thanks. Very help me

@PierreNodles
Copy link

PierreNodles commented Feb 11, 2019

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 !

@maximfringe
Copy link

maximfringe commented Mar 15, 2020

My hero!

@helldrummy
Copy link

helldrummy commented Jan 21, 2021

Bro, huge thank you

@bilalrashid300
Copy link

bilalrashid300 commented Aug 24, 2021

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