zoukankan      html  css  js  c++  java
  • js 匀速运动到100和到300

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style>
    #div1 {width:100px; height:100px; background:red; position:absolute; left:600px; top:50px;}
        #div2 {width:1px; height:300px; background:black; position:absolute; left:300px; top:0}
        #div3 {width:1px; height:300px; background:black; position:absolute; left:100px; top:0}
        </style>
        <script>
            var timer=null;
            function startMove(iTarget)
        {
            var oDiv=document.getElementById('div1');
            
            clearInterval(timer);
            
            timer=setInterval(function() {
                //var speed=(300-oDiv.offsetLeft)/10;
                //speed=Math.ceil(speed);
                
                //speed=speed>0?Math.ceil(speed):Math.floor(speed);
                var speed=0;
                
                if(oDiv.offsetLeft<iTarget)
                    {
                        speed=7;
                    }
                else
                    {
                        speed=-7;
                    }
                if(Math.abs(iTarget-oDiv.offsetLeft)<=7)
                    {
                        clearInterval(timer);
                        oDiv.style.left=iTarget+'px';
                    }
                else
                    {
                        oDiv.style.left=oDiv.offsetLeft+speed+'px';
                    }
                
                
                
                
                
                //document.title=oDiv.offsetLeft ;
            }, 30);
        }
        </script>
    </head>
    
    <body>
    <input type="button" value="到100" onClick="startMove(100)"/>
    <input type="button" value="到300" onClick="startMove(300)"/>
    <div id="div1">
    </div>
    <div id="div2"></div>
    <div id="div3"></div>
    </body>
    </html>
  • 相关阅读:
    vuejs 实战 双向数据绑定
    ubuntu16安装cuda,cudnn,gpu版opencv
    ubuntu编译安装nginx并且配置流服务器
    安装使用mongodb
    c++ 编译安装ffmpeg
    apache2 日志文件太大的解决方案
    sql注入
    制作自己的电子词典
    python传递可变参数
    工厂模式
  • 原文地址:https://www.cnblogs.com/bedfly/p/12297181.html
Copyright © 2011-2022 走看看