how to turn off mousewheel in jquery

0

Issue

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;
  });
})

Solution

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.

Answered By – Rory McCrossan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More