其他分享
首页 > 其他分享> > Dom 动画

Dom 动画

作者:互联网

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            #container{
                width: 400px;
                height: 400px;
                position: relative;
                background: cadetblue;
            }
            #animate{
                width: 50px;
                height: 50px;
                position: absolute;
                background: red;
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div id="animate">
                here is DH
            </div>
        </div>
        
        <button type="button" onclick="myMove()">click</button>
        <script >
            function myMove(){
                var elem=document.getElementById("animate");
                var pos=0;
                var id=setInterval(frame,5);
                function frame(){
                    if(pos==350){
                        //停止
                        clearInterval(id);
                    }else{
                        pos++;
                        elem.style.top=pos+'px';
                        elem.style.left=pos+'px';
                    }
                }
            }
        </script>
    </body>
</html>

 

标签:动画,Dom,frame,elem,pos,var,animate,height
来源: https://www.cnblogs.com/lwx11111/p/16029788.html