3

I don't want to disable the mouse scroll. I want to disable the click on the mouse wheel to scroll by moving the mouse up or down.

I've managed to do it for Chrome, IE, Opera and Safari, but not for Firefox.

Here's what I've used:

$(document).mousedown(function(e) {
    if(e.button == 1){  //also tried with if(e.which == 2){
        e.preventDefault();
        return false;
    }
});

Live demo

Nitin Varpe
  • 10,450
  • 6
  • 36
  • 60
Alvaro
  • 40,778
  • 30
  • 164
  • 336

3 Answers3

3

You can disable this functionality by going to "about:config" and changing "general.autoScroll" to "false" (double-click on the record).

Jon
  • 31
  • 2
  • can you please elaborate? – Enamul Hassan Dec 19 '15 at 01:48
  • manetsus - I'm not sure what your are asking. Do you understand the original request? Have you tried my solution? It seems straight forward. Here's my solution restated. You can disable this functionality in Firefox by entering "about:config" in the address bar then selecting "config" in the list. In the resulting configuration listing change "general.autoScroll" to "false" by double clicking on the record. – Jon Dec 20 '15 at 04:23
  • I think I get it now: although this is a valid answer to the OP question (when read a certain way), it is not what was meant (I guess). Funny thing is: This is the answer that I needed :-) – Xan-Kun Clark-Davis Jan 14 '23 at 03:35
1

I don't think you can completely control it in Firefox.

You can make it snap back to the top of the page for example, like this:

$(document).on('mouseup', function(e) {
    if (e.button == 1) {
        window.scroll(0, 0);
    }
});

If you keep track of the scrolling position you can make it jump back to there.

Ex-iT
  • 1,479
  • 2
  • 12
  • 20
1

here's a very awkward solution for firefox since there isn't a good way to handle it. To prevent middle click scroller to appear in Firefox, make sure that <body> size is always less than window size, plus additionally putting <body style="overflow:hidden;">

Jacky Cheng
  • 1,536
  • 1
  • 10
  • 22