防止鼠标中键滚动 [英] Prevent middle mouse click scrolling

查看:82
本文介绍了防止鼠标中键滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来阻止鼠标中键单击导致浏览器开始滚动,并显示小滚动罗盘".

I'm looking for a way to stop the middle mouse click from causing the browser to start scrolling, and showing the little scroll 'compass'.

我已经见过使用javascript禁用中键滚动,但是该解决方案比我想要的更加hacky,并且没有似乎不是我可以实际使用的东西.

I have seen Disabling middle click scrolling with javascript however the solution is a bit more hackey than I would like, and doesn't seem like something I could actually use.

我正在寻找更明确的这是您的操作方式"或您不能这样做,儿子".

我当然可以接受各种黑客手段和变通办法.

I am of course open to hacks and workarounds.

只是因为S.O.问题看起来与代码更好,这是当我单击鼠标右键或鼠标中键时用来关闭工具提示的内容.

Just because S.O. questions look nicer with code, here is what I am using to close tooltips when right or middle clicking.

msg.mousedown(function(e) {
    if (e.which == 2) {   //middle mouse click
        msg.hide();
        e.preventScrolling();   //if only this worked...
    }
    else if (e.which == 3) {   //right mouse click
        msg.hide();
    }
}).bind('contextmenu', function(e) {
    e.preventDefault();
}).click(function(e) {
    e.stopPropagation();
});

jQuery,JavaScript,随便,让我们现在都玩的很好:)

与阻止页面滚动相比,我对防止小滚动罗盘"更感兴趣.我想从我的最初描述来看并不太清楚.

I'm more interested in preventing the little scroll 'compass' than stopping the page from scrolling. I guess that wasn't very clear from my initial description.

推荐答案

使用:

$('body').mousedown(function(e){if(e.button==1)return false});

这在Chrome上有效: http://jsfiddle.net/PKpBN/3/

This works on Chrome: http://jsfiddle.net/PKpBN/3/

这篇关于防止鼠标中键滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆