How to distinguish between left and right mouse click with jQuery

后端 未结 17 2705
独厮守ぢ
独厮守ぢ 2020-11-21 22:36

How do you obtain the clicked mouse button using jQuery?

$(\'div\').bind(\'click\', function(){
    alert(\'clicked\');
});

this is trigger

17条回答
  •  失恋的感觉
    2020-11-21 22:42

    $(document).ready(function () {
        var resizing = false;
        var frame = $("#frame");
        var origHeightFrame = frame.height();
        var origwidthFrame = frame.width();
        var origPosYGrip = $("#frame-grip").offset().top;
        var origPosXGrip = $("#frame-grip").offset().left;
        var gripHeight = $("#frame-grip").height();
        var gripWidth = $("#frame-grip").width();
    
        $("#frame-grip").mouseup(function (e) {
            resizing = false;
        });
    
        $("#frame-grip").mousedown(function (e) {
            resizing = true;
        });
        document.onmousemove = getMousepoints;
        var mousex = 0, mousey = 0, scrollTop = 0, scrollLeft = 0;
        function getMousepoints() {
            if (resizing) {
                var MouseBtnClick = event.which;
                if (MouseBtnClick == 1) {
                    scrollTop = document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop;
                    scrollLeft = document.documentElement ? document.documentElement.scrollLeft : document.body.scrollLeft;
                    mousex = event.clientX + scrollLeft;
                    mousey = event.clientY + scrollTop;
    
                    frame.height(mousey);
                    frame.width(mousex);
                }
                else {
                    resizing = false;
                }
            }
            return true;
    
        }
    
    
    });
    

提交回复
热议问题