• JS抛物线运动


    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="{CHARSET}">
            <title></title>
            <style type="text/css">
                #box{background: greenyellow;
                    border-radius: 50%;
                     90px;
                    height: 90px;
                    position: absolute;
                    left: 20px;
                    top: 200px;                
                    }
            </style>
            <script type="text/javascript">
                onload=function(){
                    var oBox=document.getElementById("box");
                    //给一个速度
                    //水平速度
                    var xSpeed=10;
                    //垂直速度
                    var ySpeed=-30;
                    var timer=setInterval(function(){
                        ySpeed+=3;
                        oBox.style.left=xSpeed+oBox.offsetLeft+"px";
                        oBox.style.top=ySpeed+oBox.offsetTop+"px";
                        //边界判断
                        var clientHeight=document.documentElement.clientHeight||document.body.clientHeight;
                        if (oBox.offsetTop>=clientHeight-oBox.offsetHeight) {
                            //修正位置,正好触底
                            oBox.style.top=clientHeight-oBox.offsetHeight+"px";
                            //修正y的速度,使其向相反的方向运动,并且速度越来越小
                            ySpeed *= -0.6;
                        }
                    },100)
                    //处理一下水平方向的速度,让其越来越慢,最后变为0
                    var timer2 = setInterval(function(){
                        --xSpeed <=0 ? clearInterval(timer2) : "";
                        
                    },2000);
                    
                    
                }
            </script>
        </head>
        <body>
            <div id="box" >
                
            </div>
        </body>
    </html>

  • 相关阅读:
    阅读《构建之法》
    准备工作
    课程总结
    第十四周总结
    第十三周总结
    Flex撑开
    多行文本展示为省略号样式的react组件
    如何在Spring Boot 中动态设定与执行定时任务
    System.arraycopy() 和 Arrays.copyOf() 的区别说明
    使用反射机制,获取 ArrayList 的容量大小
  • 原文地址:https://www.cnblogs.com/qingxh/p/6266320.html
Copyright © 2020-2023  润新知