This code disabled mouse scroll functionality, when i click on the document.
$(document).on("click", function () {
window.onmousewheel = function (e) {
e.preventDefault();
}
});
but, this working in all browsers except Firefox. tell please, how to make this code as cross-browser ?
The Firefox Accessibility Service must be enabled in order for scrolling capture to work. To enable the accessibility service: In Firefox, click the menu button and choose Options. Select the Security & Privacy panel.
1) Right click on the Mozilla Firefox on the taskbar of windows and select 'Size'.
hello roman, try this: enter '''about:config''' into the firefox address bar (confirm the info message in case it shows up) & search for the preference named '''mousewheel. default. delta_multiplier_y'''. double-click it and change its value to '''-100'''.
Firefox is still very much alive and well as Mozilla has no plans to stop development of their web browsers for desktop (Windows, macOS, Linux) and mobile versions for iOS and Android.
Firefox doesn't support .onmousewheel
, you have to use the DOMMouseScroll
event instead:
$(document).on( "mousewheel DOMMouseScroll", function(e){
e.preventDefault();
});
Firefox does not support the onmousewheel
name for this event. You'll need to do it with the DOMMouseScroll
event instead.
To detect whether onmousewheel
is supported, you can do something like this:
var cancelscroll = function(e) {
e.preventDefault();
};
if ("onmousewheel" in document) {
document.onmousewheel = cancelscroll;
} else {
document.addEventListener('DOMMouseScroll', cancelscroll, false);
}
Note that you needn't do this on DOM ready: the document will always be available to bind to, so you can do it immediately.
You ask how to remove the event listener in each case. A similar conditional will do the trick:
if ("onmousewheel" in document) {
document.onmousewheel = function() {};
} else {
document.removeEventListener('DOMMouseScroll', cancelscroll, false);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With