筋斗云导航

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    <style>
*{margin: 0; padding: 0;}
ul {list-style:none;}
body {
background-color: #000;
}
.nav {
width: 800px;
height: 42px;
background:url("rss.png") no-repeat right center #fff;
margin: 100px auto;
border-radius: 5px;
position: relative;
}
.cloud {
width: 83px;
height: 42px;
position: absolute;
top: 0;
left: 0;
background: url(cloud.gif) no-repeat;
}
.nav ul {
position: absolute;
top: 0;
left: 0;
}
.nav li {
float: left;
width: 88px;
height: 42px;
line-height: 42px;
text-align: center;
color: #000;
cursor: pointer;
}
</style>
</head>
<body>
<div class="nav" id="nav">
<span class="cloud" id="cloud"></span>
<ul id="box">
<li>首页新闻</li>
<li>千锋师资</li>
<li>千锋活动策划</li>
<li>企业文化</li>
<li>招聘信息</li>
<li>公司简介</li>
<li>上海校区</li>
<li>广州校区</li>
</ul>
</div>
</body>
</html>
    <script type="text/javascript">
        var cloud = document.getElementById("cloud");
        var list = document.getElementsByTagName("li");
        var current = 0; //记录当前点击的位置
        var timer = null;
        
        function starMove( obj,target ){
            clearInterval( obj.timer );
            obj.timer = setInterval( function(){
                var speed = ( target - obj.offsetLeft )/10;
                speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
                if( obj.offsetLeft == target ){
                    clearInterval( obj,timer );
                }else{
                    obj.style.left = obj.offsetLeft + speed + "px";
                }
            },30 )  
        }
        
        for( var i = 0 ; i < list.length ; i++ ){
            list[i].onmouseenter = function(){
                starMove( cloud, this.offsetLeft );
            }
            list[i].onmouseleave = function(){
                starMove( cloud, current );
            }
            list[i].onclick = function(){
                current = this.offsetLeft;
            }       
        }
    </script>

转载于:https://www.cnblogs.com/tis100204/p/10328775.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值