我整理修改的一个精典右键菜单JS代码

发布时间:2007年11月02日      浏览次数:2916 次
将以下代码保存到一个*.js文件
然后通过<script src="*.js"></script>包含到需要使用此功能的页面即可.
<!--
document.write("<STYLE type=text/css>");
document.write(".cMenu {FILTER: alpha(opacity=0);BACKGROUND-COLOR: #D6D3CE;BORDER-
BOTTOM: #666666 2px solid; BORDER-LEFT: #E4E4E4 2px solid; BORDER-RIGHT: #666666 2px
solid; BORDER-TOP: #E4E4E4 2px solid; COLOR: #000000; CURSOR: default; FONT-SIZE: 9pt;
color:#000000;FONT-WEIGHT: normal; LINE-HEIGHT: 20px; POSITION: absolute; VISIBILITY:
hidden; WIDTH: 110px;text-align:left;}");
document.write(".div_title {background-color:#333;font-weight:bold;color:#fff;text-
align:center;}");
document.write(".menuitems {font-size:9pt;MARGIN: 2px;PADDING-BOTTOM: 0px;PADDING-LEFT:
5px;PADDING-RIGHT: 5px;PADDING-TOP: 0px;}");
document.write("</STYLE>");
//document.write("<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0
id=WebBrowser width=0></OBJECT>");
document.write("<RIGHTCLICK>");
document.write("<!--[if IE]>");
document.write("<DIV class=cMenu id=ie5menu onclick=jumptoie5() onmouseout=lowlightie5()
onmouseover=highlightie5()>");
      document.write("<DIV class=div_title>【 网站导航 】</DIV>");
      document.write("<DIV class=menuitems url='#'><span style='font-
Family:webdings'>4</span> 网站首页</DIV>");
document.write("<DIV class=menuhr><hr style='width:100%'></DIV>");
      document.write("<DIV class=menuitems url='#'><span style='font-
Family:webdings'>4</span> 菜单标题</DIV>");
      document.write("<DIV class=menuitems url='#'><span style='font-
Family:webdings'>4</span> 菜单标题</DIV>");
      document.write("<DIV class=menuitems url='#'><span style='font-
Family:webdings'>4</span> 菜单标题</DIV>");
      document.write("<DIV class=menuitems url='#'><span style='font-
Family:webdings'>4</span> 菜单标题</DIV>");
document.write("<DIV class=menuhr><hr style='width:100%'></DIV>");
      document.write("<DIV class=menuitems url='#'><span style='font-
Family:webdings'>4</span> 菜单标题</DIV>");
document.write("</DIV>");
document.write("<![endif]-->");
document.write("</RIGHTCLICK>");
///////////////////////////////////////////////////////////////////////////////////////
var intDelay=10;
var intInterval=5;
function showmenuie5(){
var rightedge=document.body.clientWidth-event.clientX
var bottomedge=document.body.clientHeight-event.clientY
if (rightedge<ie5menu.offsetWidth)
ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth
else
ie5menu.style.left=document.body.scrollLeft+event.clientX
if (bottomedge<ie5menu.offsetHeight)
ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight
else
ie5menu.style.top=document.body.scrollTop+event.clientY
ie5menu.style.visibility="visible"
//ie5menu.style.visibility=""
ie5menu.filters.alpha.opacity=0
GradientShow()
return false
}
function hidemenuie5(){
//ie5menu.style.visibility="hidden"
GradientClose()
}
function highlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
}
}
function lowlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="#000000"
}
}
function jumptoie5(){
if (event.srcElement.className=="menuitems"){
if (event.srcElement.url != ''){
if (event.srcElement.getAttribute("target")!=null)
window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
else
window.location=event.srcElement.url
}
}
}
function GradientShow()
{
ie5menu.filters.alpha.opacity+=intInterval
if (ie5menu.filters.alpha.opacity<100) setTimeout("GradientShow()",intDelay)
}
function GradientClose()
{
ie5menu.filters.alpha.opacity-=intInterval
if (ie5menu.filters.alpha.opacity>0) {
setTimeout("GradientClose()",intDelay)
}
else {
ie5menu.style.visibility="hidden"
}
}
function ChangeBG()
{
oEl=event.srcElement
if (oEl.style.background!="navy") {
oEl.style.background="navy"
}
else {
oEl.style.background="#cccccc"
}
}
///////////////////////////////////////////////////////////////////////////////////////
if (document.all&&window.print){
ie5menu.className="cMenu"
document.oncontextmenu=showmenuie5
document.body.onclick=hidemenuie5
}
//-->
文章来源:桂林唯创网络
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!