多物体缓冲动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多物体 缓冲动画</title>
    <style>
        ul,li{
           list-style:none;
        }
        ul li{
            width:200px;
            height:100px;
            background: yellow;
            margin-bottom: 20px;
        }
    </style>
    <script>
        window.onload=function(){
            var aLi=document.getElementsByTagName('li');
            for(var i=0;i<aLi.length;i++){
                aLi[i].timer=null;
                aLi[i].onmouseover=function(){
                    startMove(this,400);
                };
                aLi[i].onmouseout=function(){
                    startMove(this,200);
                };
            }
        };
        function startMove(obj,iTarget){
            clearInterval(obj.timer);
            obj.timer=setInterval(function(){
                var speed=(iTarget-obj.offsetWidth)/8;
                speed = speed>0?Math.ceil(speed):Math.floor(speed);
                if(obj.offsetWidth==iTarget){
                    clearInterval(obj.timer);
                }else{
                    obj.style.width=obj.offsetWidth+speed+'px';
                }
            },30)
        }
    </script>
</head>
<body>
    <ul>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</body>
</html>

 

posted @ 2019-11-29 14:33  Fourteen  阅读(113)  评论(0编辑  收藏  举报