Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
41
rated 0 times [  44] [ 3]  / answers: 1 / hits: 19083  / 10 Years ago, thu, september 18, 2014, 12:00:00

I have two pages, these are the conditions I cannot achieve, please let me know if it is not possible.




  1. In one page, I need to disable the mouse-wheel to scroll up. So when I scroll up with mouse-wheel nothing happens, but when I scroll down the page scrolls.


  2. In the other page, I want the exact opposite, I need to disable the scrolling down on mouse-wheel. So when I scroll down nothing happens, but when I scroll up the page scrolls.




This is all i really need, but if you think I need to explain more, please let me know, thank you.


More From » jquery

 Answers
24

Case of preventing mouse scroll down (for mouse scroll up just change comparison operator to '<'):



$(window).on(wheel mousewheel, function(e){
if(e.originalEvent.deltaY > 0) {
e.preventDefault();
return;
} else if (e.originalEvent.wheelDeltaY < 0) {
e.preventDefault();
return;
}
});


We need to check for two values because of cross-browser issues.



jsFiddle link



P. S. Warning. Since later versions of Chrome decides to treat all window events as passive by default, the code above won't work in Chrome. Will come with a better solution and update this answer ASAP.


[#69413] Tuesday, September 16, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
destiniemartinac

Total Points: 92
Total Questions: 106
Total Answers: 111

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
destiniemartinac questions
Thu, Oct 28, 21, 00:00, 3 Years ago
Sat, Mar 13, 21, 00:00, 3 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
;