• 封装运动四:缓冲运动


    缓冲运动思想:

    改变速度,即给速度除以一个整数即可。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            *{
                padding:0;
                margin:0;
            }
           #box{
               100px;
               height:100px;
               background: red;
               position:absolute;
               top:100px;
               left:0;
           }
           #target{
               height:400px;
               400px;
               border-right:1px solid black
           }
    
        </style>
    </head>
    <body>
        <button id = "rbtn">fly</button>
        <button id = "lbtn">back</button>
        <div id = "target"><div id = "box"></div></div>
    </body>
    </html>
    <script src = "tool.js"></script>
    <script>
        var oDiv = ById('box');
        var orBtn = ById('rbtn');
        var olBtn = ById('lbtn');
        var timer = null;
        orBtn.onclick = function(){
            divmove(400);
        }
        olBtn.onclick = function(){
            divmove(0);
        }
        function divmove(target){
            clearInterval(timer);
           timer = setInterval(function(){
              var speed = (target - oDiv.offsetLeft)/10;
              //此处会有一个bug,oDiv回不到目标值,所以,需要向上取整、向下取整。
              speed=speed > 0 ? Math.ceil(speed) : Math.floor(speed);
              if( target ==speed){
                  clearInterval(timer);
              }else{
                  oDiv.style.left = oDiv.offsetLeft + speed + "px" ;
              }
           },30)
        }
    </script>
  • 相关阅读:
    vs code插件
    各大厂RTSP取流的URI
    关于VLC无法播放rtsp的问题分析
    VLC查看日志的方法
    wireshark的过滤命令
    vs编译完提示不支持尝试的执行操作
    vs2015的密钥
    VS制作dll、def文件的使用、dll加入工程使用
    python之NLP数据清洗
    python 生成词云
  • 原文地址:https://www.cnblogs.com/kinoko-1009/p/10282160.html
Copyright © 2020-2023  润新知