jQuery mouseup function on left mouse button only?

▼魔方 西西 提交于 2019-12-30 09:09:13

问题


I have this element which animates on a mouseup function, but right now, it works for both the left and right buttons. Is there any way to only use the left button?

$(document).ready(function() {
    $("div").mouseup(function() {
        top: "-101%"
    });
});

回答1:


You can check to see which mouse button was pressed using e.which (1 is primary, 2 is middle and 3 is secondary):

$(document).ready(function() {
    $("div").mouseup(function(e) {
        if (e.which != 1) return false;    // Stops all non-left-clicks

        ...
    });
});


来源:https://stackoverflow.com/questions/14048344/jquery-mouseup-function-on-left-mouse-button-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!