Home  >  Article  >  Web Front-end  >  jquery short right-click menu compatible with multiple browsers_jquery

jquery short right-click menu compatible with multiple browsers_jquery

WBOY
WBOYOriginal
2016-05-16 18:37:28828browse

复制代码 代码如下:

$(function(){
document.oncontextmenu=function(){return false;}//屏蔽右键
document.onmousemove=mouseMove;//记录鼠标位置
});
var mx=0,my=0;
function mouseMove(ev){Ev=ev||window.event;var mousePos=mouseCoords(Ev);mx=mousePos.x;my=mousePos.y;}
function mouseCoords(ev){
if(ev.pageX||ev.pageY){return{x:ev.pageX,y:ev.pageY};}
return{x:ev.clientX,y:ev.clientY $(document).scrollTop()};
}

$.fn.extend({RightMenu: function(id,options){options = $.extend({menuList:[]},options);var menuCount=options.menuList.length;
if (!$("#" id)[0]){
var divMenuList="
    ";
    for(var i=0;idivMenuList ="
  • " options.menuList[i].menuName "
  • ";
    }
    divMenuList = "
";
$("body").append(divMenuList).find("#" id).hide().find("li")
.bind("mouseover",function(){$(this).addClass("RM_mouseover");})
.bind("mouseout",function(){$(this).removeClass("RM_mouseover");});
$(document).click(function(){$("#" id).hide();});
}
return this.each(function(){
this.oncontextmenu=function(){
        /*这段 判断鼠标移到页面的最右侧或者最下侧 防止出现滚动条 {*/
var mw=$('body').width(),mhh=$('html').height(),mbh=$('body').height(),
w=$('#' id).width(),h=$('#' id).height(),
mh=(mhh>mbh)?mhh:mbh;//最大高度 比较html与body的高度
if(mhif(mw      /*} 当然也可以直接跳过*/
$("#" id).hide().css({top:my,left:mx}).show();
}
});
}
});

在线演示 右键点击测试效果

打包下载
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn