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
3 Answers
Reset to default 8You 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
版权声明:本文标题:javascript - Disable scrolling on mouse wheel click on Firefox? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741975661a2408105.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论