admin管理员组

文章数量:1315355

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

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

Share Improve this question edited May 14, 2014 at 9:28 Nitin Varpe 10.7k6 gold badges41 silver badges63 bronze badges asked May 14, 2014 at 9:24 AlvaroAlvaro 41.6k31 gold badges172 silver badges347 bronze badges 2
  • 1 stackoverflow./questions/8189840/… – Vikram Jakkampudi Commented May 14, 2014 at 9:38
  • @VikramJakkampudi that's not about the click, but about the scroll... – Alvaro Commented May 14, 2014 at 10:46
Add a ment  | 

3 Answers 3

Reset to default 8

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

I don't think you can pletely 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.

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;">

本文标签: javascriptDisable scrolling on mouse wheel click on FirefoxStack Overflow