Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.onmousewheel in Firefox

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 ?

like image 373
ოთო შავაძე Avatar asked Jul 04 '12 12:07

ოთო შავაძე


People also ask

Why is my scroll wheel not working in Firefox?

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.

How do I make Firefox fit my screen?

1) Right click on the Mozilla Firefox on the taskbar of windows and select 'Size'.

How do I invert scrolling in Firefox?

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'''.

What happened to Mozilla Firefox?

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.


2 Answers

Firefox doesn't support .onmousewheel, you have to use the DOMMouseScroll event instead:

$(document).on( "mousewheel DOMMouseScroll", function(e){
    e.preventDefault();
});
like image 180
Esailija Avatar answered Oct 08 '22 18:10

Esailija


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);
}
like image 44
lonesomeday Avatar answered Oct 08 '22 18:10

lonesomeday