取消鼠标右击默认功能,并添加事件

//鼠标右击事件
//封装
function mouseRightClick (obj, callback) {
    //禁止浏览器默认事件
    $(document).delegate(obj,'contextmenu', function (e) {
        e.preventDefault();
    });
    //给选择器obj绑定右键事件
    $(document).delegate(obj,'mousedown', function (e) {
        var $t = $(this);
        if (e.which == 3) {
            if (typeof callback == 'function') {
                //右键执行回调函数
                callback($t,e.pageX,e.pageY);
            }
        }
    });
}
mouseRightClick('.circle',function(t,x,y){
     //t为当前右击的元素,x,y为当前鼠标点击时的位子;
    //调用 需要注意得是 如果用到x,y最好给它们偏移及格像素;
});

猜你喜欢

转载自blog.csdn.net/Chou_Junn/article/details/84241615