zoukankan      html  css  js  c++  java
  • 弹力球小练习

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>baoll</title>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            #myball{
                width: 128px;
                height: 128px;
                position: absolute;
                border-radius: 50%;
                background-color: red;
            }
        </style>
    </head>
    <body>
    <div id="myball"></div>
    <script>
        var myBall = document.getElementById("myball");
        var ys = 0;
        var yv = 10;
        var xs = 0;
        var xv = 10;
        var cilentHeight = document.documentElement.clientHeight;
        var cilentWidth = document.documentElement.clientWidth;
        var ballHeight = 128;
        var ballWidth = 128;
        var heightDifference = cilentHeight-ballHeight;
        var widthDifference = cilentWidth-ballWidth;
        setInterval(function(){
            //y轴数据;
            ys += yv;
            if(ys >= heightDifference){
                ys = heightDifference;
                yv = -yv;
            }
            if(ys <= 0){
                yv = -yv;
            }
            myBall.style.top = ys + "px";
    
            //x轴数据;
            xs += xv;
            if(xs >= widthDifference){
                xs = widthDifference;
                xv = -xv;
            }
            if(xs <= 0){
                xv = -xv;
            }
            myBall.style.left = xs + "px";
        },10)
    </script>
    </body>
    </html>
  • 相关阅读:
    面向过程
    生成器
    迭代器
    装饰器
    函数及嵌套
    字符编码与文件操作
    linux_ssh
    LNMP
    BZOJ 3238: [Ahoi2013]差异
    BZOJ 3998: [TJOI2015]弦论
  • 原文地址:https://www.cnblogs.com/-CLAY-/p/clientwidth.html
Copyright © 2011-2022 走看看