jQuery mouseup function on left mouse button only?

前端 未结 1 1287
谎友^
谎友^ 2021-01-12 15:25

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 <

相关标签:
1条回答
  • 2021-01-12 15:56

    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
    
            ...
        });
    });
    
    0 讨论(0)
提交回复
热议问题