弹性菜单-js

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>弹性菜单</title>
<style>
*{ padding:0; margin:0; list-style:none;}
#ul1{ width:800px; position:relative; margin:10px auto; background:#9C0; height:30px;}
#ul1 li{ width:200px; height:30px; line-height:30px; text-align:center; float:left; z-index:2; position:relative;}
#ul1 li a{ display:block}
#ul1 li.box{ position:absolute; background:#ff0; left:0; top:0; z-index:1;}
</style>
</head>
<script>
window.onload=function(){
var oUl=document.getElementById('ul1');
var aLi=oUl.children;
var oBox=aLi[aLi.length-1];

for(var i=0;i<aLi.length-1;i++){
aLi[i].onmouseover=function(){
startMove(oBox,this.offsetLeft);
};
}
};
var i=0;
function startMove(obj,iTarget){
obj.speed=obj.speed||0;
obj.left=obj.left||obj.offsetLeft;

clearInterval(obj.timer);
obj.timer=setInterval(function(){
obj.speed+=(iTarget-obj.left)/5;
obj.speed*=0.7;
obj.left+=obj.speed;
obj.style.left=Math.round(obj.left)+'px';

if(Math.abs(obj.speed)<1&&obj.offsetLeft==iTarget){
clearInterval(obj.timer);
}
document.title=i++;

},30);
}
</script>
<body>
<ul id="ul1">
<li><a href="http://www.gaigaiming.com">首页</a></li>
<li><a href="javascript:;">作品</a></li>
<li><a href="javascript:;">用户</a></li>
<li><a href="javascript:;">论坛</a></li>
<li class="box"></li>
</ul>
</body>
</html>

 

利用定位,运动展示弹性菜单。

先清再定时器。

DEMO

《弹性菜单-js》上有2条评论

  1. Pingback: toms outlet
  2. Pingback: lebron 11

发表评论

电子邮件地址不会被公开。