欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

JS实现不使用图片仿Windows右键菜单效果代码_javascript技巧

程序员文章站 2022-03-24 17:22:44
...
本文实例讲述了JS实现不使用图片仿Windows右键菜单效果代码。分享给大家供大家参考,具体如下:

这里演示JS不使用图片仿Windows右键菜单效果,这款代码灵活使用了文鼎字,配合CSS和JS做出了这个和系统右键菜单很相似的东东。

运行效果截图如下:

JS实现不使用图片仿Windows右键菜单效果代码_javascript技巧

在线演示地址如下:

http://demo.jb51.net/js/2015/js-windows-right-button-menu-codes/

具体代码如下:



极酷的多级右键菜单
\n"; HTMLstr += ""; HTMLstr += "\n"; HTMLstr += "\n"; } function AddExtendMenu(id,img,wh,name,parent) { var TempStr = ""; eval("A_"+parent+".length++"); eval("A_"+parent+"[A_"+parent+".length-1] = id"); TempStr += "
\n"; TempStr += "\n"; TempStr += ""; TempStr += "
\n"; TempStr += "
\n"; TempStr += ""; TempStr += ""; HTMLstr = HTMLstr.replace("",TempStr); eval("A_"+id+" = new Array()"); TempStr = ""; TempStr += "\n"; TempStr += " "; TempStr += "0 "+name+" 4"; TempStr += " \n"; TempStr += ""; HTMLstr = HTMLstr.replace("",TempStr); } function AddItem(id,img,wh,name,parent,location) { var TempStr = ""; var ItemStr = ""; if(id == "sperator") { TempStr += ItemStr+"\n"; TempStr += "
"; TempStr += ""; HTMLstr = HTMLstr.replace("",TempStr); return; } if(HTMLstr.indexOf(ItemStr) != -1) { alert("I_"+id+"already exist!"); return; } TempStr += ItemStr+"\n"; TempStr += " "; TempStr +=""+wh+" "+ name+" ";// TempStr += " \n"; TempStr += ""; HTMLstr = HTMLstr.replace("",TempStr); } function GetMenu() { return HTMLstr; } function I_OnMouseOver(id,parent) { var Item; if(parent != "rbpm") { var ParentItem; ParentItem = eval("P_"+parent); ParentItem.className="over"; } Item = eval("I_"+id); Item.className="over"; HideAll(parent,1); } function I_OnMouseOut(id) { var Item; Item = eval("I_"+id); Item.className="out"; } function I_OnMouseUp(id,parent,location) { var ParentMenu; window.event.cancelBubble=true; OnClick(); ParentMenu = eval("E_"+parent); ParentMenu.display="none"; if(location == null) eval("Do_"+id+"()"); else window.open(location); } function P_OnMouseOver(id,parent) { var Item; var Extend; var Parent; if(parent != "rbpm") { var ParentItem; ParentItem = eval("P_"+parent); ParentItem.className="over"; } HideAll(parent,1); Item = eval("P_"+id); Extend = eval("E_"+id); Parent = eval("E_"+parent); Item.className="over"; Extend.style.display="block"; Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth-4; if(Extend.style.posLeft+Extend.offsetWidth > document.body.scrollLeft+document.body.clientWidth) Extend.style.posLeft=Extend.style.posLeft-Parent.offsetWidth-Extend.offsetWidth+8; if(Extend.style.posLeft document.body.scrollTop+document.body.clientHeight) Extend.style.posTop=document.body.scrollTop+document.body.clientHeight-Extend.offsetHeight; if(Extend.style.posTop document.body.scrollLeft+document.body.clientWidth) PopMenu.style.posLeft=document.body.scrollLeft+document.body.clientWidth-PopMenu.offsetWidth; if(PopMenu.style.posLeft document.body.scrollTop+document.body.clientHeight) PopMenu.style.posTop=document.body.scrollTop+document.body.clientHeight-PopMenu.offsetHeight; if(PopMenu.style.posTop
请点击右键