转圈圈动画animation

来源:互联网 发布:智业软件招聘 编辑:程序博客网 时间:2024/04/29 17:15
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
 <meta charset="utf-8" />
    <style>
        *{
            margin:0;
            padding:0;
        }
       
        #circle{
            background-color:coral;
            height:100px;
            width:100px;
            position:relative;
         
           
        }
    </style>
    <script>
        window.onload = function () {

            for (var i = 0; i < 20; i++) {
                var Odiv = document.getElementById('circle');
                // Odiv.onmouseover = function () {

                StartMove(window.screen.availWidth - 100, 'offsetLeft', 'left', function () {
                    StartMove(window.screen.availHeight - 170, 'offsetTop', 'top', function () {
                        StartMove(0, 'offsetLeft', 'left', function () {
                            StartMove(0, 'offsetTop', 'top')
                        })
                    })
                });
            }

        }


            // }
            var timer = null;
            function StartMove(itarget, key, direction, fn) {
                clearInterval(timer);
                var Odiv = document.getElementById('circle');
                timer = setInterval(function () {
                    var speed = (itarget - Odiv[key]) / 5;
                    speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
                    if (Odiv[key] == itarget) {
                        clearInterval(timer);
                        if (fn) {
                            fn();
                        }
                    }
                    else {
                        Odiv.style[direction] = Odiv[key] + speed + 'px';
                    }
                }, 30)
            }

       
    </script>
</head>
<body>
    <div id="circle"></div>
   
</body>
</html>
1 0
原创粉丝点击