I want to disable the mouse wheel in jQuery and I did it but I'm getting this error
jquery.min.js:2 [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/6662647093133312
This is the code in JS file:
$(document).ready(() => {
$(window).bind("mousewheel", function() {
return false;
});
})
CodePudding user response:
The issue is because you cannot call preventDefault()
on passive events, such as mousewheel
is - among others.
To fix the issue you can set passive: false
when you bind the event handler:
window.addEventListener('wheel', e => e.preventDefault(), {
passive: false
});
/* just to make the scrollbar appear in this demo */
body { height: 5000px; }
However, I would strongly suggest you do not do this. Preventing users from navigating your site using the very popular mouse scroll wheel will be incredibly annoying for you users - and possibly make them believe your site is malfunctioning.