zoukankan      html  css  js  c++  java
  • 妙味——弹性运动

    <!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" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style>
    *{margin: 0;padding: 0;}
    li{list-style: none;}
    ul{width:400px;height: 30px;position: relative;margin: 100px auto 0;}
    li{float: left;width: 98px;height: 28px;line-height: 28px;border: 1px solid #ccc;text-align: center;z-index: 2;position: relative;cursor: pointer;}
    .bg{width: 100px;height: 5px;overflow: hidden;background: red;border: none;position: absolute;top: 24px;left: 0;z-index: 1;}
    </style>
    <script>
    window.onload=function(){
        var oUl=document.getElementById('ul1');
        var aLi=oUl.getElementsByTagName('li');
        var oBg=aLi[aLi.length-1];
        var i=0;
    
        for(i=0;i<aLi.length-1;i++){
            aLi[i].onmouseover=function(){
                startMove(oBg,this.offsetLeft);
            };
    
        }
    };
    
    var iSpeed=0;
    var left=0;
    function startMove(obj,iTarget){
        clearInterval(obj.timer);
    
        obj.timer=setInterval(function(){
            iSpeed+=(iTarget-obj.offsetLeft)/5;
            iSpeed*=0.7;
    
            left+=iSpeed;
    
            if(Math.abs(iSpeed)<1 && Math.abs(left-iTarget)<1)
            {
                clearInterval(obj.timer);
                obj.style.left=iTarget+'px';
            }
            else
            {
                obj.style.left=left+'px';
                // document.title=obj.offsetLeft+' / '+iTarget+' / '+iSpeed;
            }
        },30);
    };
    
    </script>
    </head>
    <body>
        <ul id="ul1">
            <li>首页</li>
            <li>关于我们</li>
            <li>产品</li>
            <li>联系方式</li>
            <li class="bg"></li>
        </ul>
    </body>
    </html>

    效果如下图所示:

    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    数据库多表查询
    链表的经典习题
    数据库基本概念及简单的单表操作
    Categrory
    2021春招冲刺练习目录
    2012春招冲刺-01.01 关于Cookie、什么是闭包、BFC与盒模型
    2021春招冲刺
    JS中bind,call,apply以及new的用法与实现
    2021春招冲刺-12.30 POST与GET | JS异步任务 | 判断变量类型
    2021春招冲刺-12.29-算法、原型与原型链、文档流
  • 原文地址:https://www.cnblogs.com/baixc/p/3493089.html
Copyright © 2011-2022 走看看