当前位置:编程学习 > JAVA >>

jquery简短右键菜单例子(多浏览器兼容)

不解释, 能看明白 就看, 看不明白 就闪。

 

[javascript] $(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="<div id=\""+id+"\" class=\"div_RightMenu\"><div><ul class='ico'>"; 
        for(var i=0;i<menuCount;i++){ 
            divMenuList+="<li class=\"RMli_"+options.menuList[i].menuclass+"\" onclick=\""+options.menuList[i].clickEvent+"\">"+options.menuList[i].menuName+"</li>"; 
        } 
        divMenuList += "</ul></div><div>"; 
        $("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(mh<h+my){my=mh-h;}//超 高  
            if(mw<w+mx){mx=mw-w;}//超 宽  
            $("#"+id).hide().css({top:my,left:mx}).show(); 
        } 
    }); 
    } 
}); 
$(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="<div id=\""+id+"\" class=\"div_RightMenu\"><div><ul class='ico'>";
  for(var i=0;i<menuCount;i++){
   divMenuList+="<li class=\"RMli_"+options.menuList[i].menuclass+"\" onclick=\""+options.menuList[i].clickEvent+"\">"+options.menuList[i].menuName+"</li>";
  }
  divMenuList += "</ul></div><div>";
  $("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(mh<h+my){my=mh-h;}//超 高
   if(mw<w+mx){mx=mw-w;}//超 宽
   $("#"+id).hide().css({top:my,left:mx}).show();
  }
 });
    }
});
不解释, 能看明白 就看, 看不明白 就闪。

 


[css] *{ font-size:12px; margin:0; padding:0;} 
 
.div_RightMenu{ position:absolute; list-style:none;width:100px;} 
.div_RightMenu div{background:#bbb;position:relative;} 
.div_RightMenu ul{position:relative;background:#fff; border:1px solid #999;left:-2px;top:-2px; margin:0; padding:1px 0;} 
.div_RightMenu ul li{ list-style:none; margin:0 1px;padding:0;line-height:20px;height:20px;text-indent:25px;background-image:url(images/t.gif); background-repeat:no-repeat;cursor:pointer;border-width:1px;border-style:solid;border-color:#fff;} 
 
.div_RightMenu ul li.RMli_1{background-position:0 0;} 
.div_RightMenu ul li.RMli_2{background-position:0 -20px;} 
.div_RightMenu ul li.RMli_3{background-position:0 -40px;} 
.div_RightMenu ul li.RMli_4{background-position:0 -60px;} 
.div_RightMenu ul li.RMli_5{background-position:0 -80px;} 
.div_RightMenu ul li.RMli_6{background-position:0 -100px;} 
.div_RightMenu ul li.RMli_7{background-position:0 -120px;} 
.div_RightMenu ul li.RMli_8{background-position:0 -140px;} 
.div_RightMenu ul li.RMli_9{background-position:0 -160px;} 
.div_RightMenu ul li.RMli_10{background-position:0 -180px;} 
.div_RightMenu ul li.RMli_11{background-position:0 -200px;} 
.div_RightMenu ul li.RMli_12{background-position:0 -220px;} 
.div_RightMenu ul li.RMli_13{background-position:0 -240px;} 
.div_RightMenu ul li.RMli_14{background-position:0 -260px;} 
.div_RightMenu ul li.RMli_15{background-position:0 -280px;} 
.div_RightMenu ul li.RMli_16{background-position:0 -300px;} 
 
.div_RightMenu ul li.RM_mouseover{ background-color:#B6BDD2; border-color:#0A246A;} 
 
tr.selected{ background:#B6BDD2;} 
*{ font-size:12px; margin:0; padding:0;}

.div_RightMenu{ position:absolute; list-style:none;width:100px;}
.div_RightMenu div{background:#bbb;position:relative;}
.div_RightMenu ul{position:relative;background:#fff; border:1px solid #999;left:-2px;top:-2px; margin:0; padding:1px 0;}
.div_RightMenu ul li{ list-style:none; margin:0 1px;padding:0;line-height:20px;height:2

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,