码迷,mamicode.com
首页 > 其他好文 > 详细

抛物线

时间:2019-01-09 15:46:46      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:doc   nbsp   clear   code   html   body   doctype   abs   The   

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            #div1{
                width: 100px;
                height: 100px;
                background: red;
                position: absolute;
                top: 500px;
            }
        </style>
        <script>
            window.onload=function(){
                var oDiv=document.getElementById("div1");
                var oInput=document.getElementById("input1");
                var timer=null;
                var iSpeed=-40;
                var iSpeedX=10;
                oInput.onclick=function(){
                    startMove();
                }
                function startMove(){
                    clearInterval(timer);
                    timer=setInterval(function(){
                        iSpeed+=3;
                        var T=oDiv.offsetTop+iSpeed;
                        if(T>document.documentElement.clientHeight-oDiv.offsetHeight){
                            T=document.documentElement.clientHeight-oDiv.offsetHeight;
                            iSpeed*=-1;
                            iSpeed*=0.75;
                            iSpeedX*=0.75;
                        }
                        oDiv.style.top=T+"px";
                        oDiv.style.left=oDiv.offsetLeft+iSpeedX+"px";
                    },30)
                }
            }
        </script>
    </head>
    <body>
        <input type="button" value="开始运动" id="input1" />
        <div id="div1"></div>
    </body>
</html>

 

抛物线

标签:doc   nbsp   clear   code   html   body   doctype   abs   The   

原文地址:https://www.cnblogs.com/gxywb/p/10244567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!