【荐】JS+CSS实现兼容好带缓冲的动感网页右键菜单

代码简介:

兼容好带缓冲的动感网页右键菜单,应该来说做的非常棒,完全JavaScript的实现,我觉得挺不错,感谢作者。

代码内容:

View Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>【荐】JS+CSS实现兼容好带缓冲的动感网页右键菜单_网页代码站(www.webdm.cn)</title>
<style type="text/css">
div,body,span,ul,li {padding:
0;margin:0;font-size:12px;}
ul,ol {list
-style-type:none;}
#div1 {width:196px;height:296px;padding:2px;overflow:hidden;position:absolute;border:1px solid #
666;left:200px;top:50px;display:none;z-index=1;-webkit-box-shadow:1px 3px 

4px #
888;box-shadow:1px 3px 4px #888;-moz-box-shadow:1px 3px 4px #888;}
#ul li {width:176px;height:25px;line
-height:25px;cursor:pointer;overflow:hidden;padding-left:20px;}
.tip {width:500px;height:25px;font
-size:20px;margin:50px 200px;color:red;}
</style>
<script type="text/javascript">
var g_oDiv
={};
var oDiv
=null;
var g_iSpeed
=0;
var t
=null;
window.onload
=function(){
    opUl();
    oDiv
=document.getElementById("div1");
    oDiv.style.height
="0px";
    document.oncontextmenu
=function(ev){
            
            var oEvent
=window.event||ev;
            cancelDefault(oEvent);
            g_oDiv.MouseX
=oEvent.clientX;
            g_oDiv.MouseY
=oEvent.clientY;
            oDiv.style.left
=g_oDiv.MouseX+"px";
            oDiv.style.top
=g_oDiv.MouseY+"px";
            
/* 初始化经过背景为空 */
            var oUl
=document.getElementById("ul");
            var aLi
=oUl.getElementsByTagName("li");            
            
for(var i=0;i<aLi.length;i++){
                aLi[i].style.background
="none";
            }
            clearInterval(t);            
            doDiv();
    }
    document.body.onmousedown
=function(ev){
        var oEvent
=window.event||ev;
        clearInterval(t);
        g_iSpeed
=0;
        g_oDiv.h
=0;
        oDiv.style.height
=g_oDiv.h+"px";
        oDiv.style.display
="none";
    }
    
    
    oDiv.onmousedown
=function(ev){
        var oEvent
=window.event||ev;
        oEvent.cancelBubble
=true;
    }
    
    
}
function doDiv(ev){
    var oEvent
=window.event||ev;
    oDiv.style.display
="block";
    t
=setInterval(doMove,30);
}
function doMove(){
    
if(oDiv.offsetHeight>=302){
        g_iSpeed
*=-0.7;
        oDiv.style.height
=302+"px";
    }
    g_oDiv.h
=g_iSpeed+oDiv.offsetHeight;
    g_iSpeed
+=10;    
    oDiv.style.height
=g_oDiv.h+"px";
}
function cancelDefault(oEvent){
    
if(oEvent.preventDefault){
        oEvent.preventDefault();
    }
    
else{
        oEvent.returnValue
=false;
    }
}
/* 对li操作后的动作的定义 */
function opUl(){
    var oUl
=document.getElementById("ul");
    var aLi
=oUl.getElementsByTagName("li");
    
for(var i=0;i<aLi.length;i++){
        aLi[i].aIndex
=i;
        aLi[i].onmouseover
=function(){
            
for(j=0;j<aLi.length;j++){
                aLi[j].style.background
="none";
            }
            aLi[
this.aIndex].style.background="#ffbb66";
        }
        aLi[i].onclick
=function(){
            clearInterval(t);
            oDiv.style.display
="none";
            alert(
this.innerHTML+" 你可以在这里自定义自己的方法啦");
        }
    }
}
</script>
</head>
<body style="width:2000px;height:800px;">
<div class="tip">右键点击游览器呗</div>
    
<div id="div1">
        
<ul id="ul">
            
<li>这是第一行</li>
            
<li>这是第二行</li>
            
<li>这是第三行</li>
            
<li>这是第四行</li>
            
<li>这是第五行</li>
            
<li>这是第六行</li>
            
<li>这是第一行</li>
            
<li>这是第二行</li>
            
<li>这是第三行</li>
            
<li>这是第四行</li>
            
<li>这是第五行</li>
            
<li>这是第六行</li>
        
</ul>
    
</div>
<br />
<p><a href="http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!</p>
</body>
</html>
代码来自:http:
//www.webdm.cn/webcode/f9898177-7d2c-4bc5-8022-00f6249a2121.html

 

posted @ 2011-07-24 11:49  网页代码站  阅读(298)  评论(0编辑  收藏  举报