zoukankan      html  css  js  c++  java
  • div简单水平移动效果

      将img放置在div中,通过移动div达到移动img的效果,下面是水平移动。

      html文件:

    <div style="float:left; 1000px">
        <div style="position:absolute; left:10px; float:left; 250px" id="fIdiv">
            <img id="firstImg" src="images/sjz1.JPG" />
        </div>
        <div style="position:absolute; left:220px; float:left; 250px" id="sIdiv">
            <img id="secondImg" src="images/sjz2.jpg" />
        </div>
    </div>

      js文件:

    var i=10;
    function transferImages(){
        var first = document.getElementById("fIdiv");
        var second = document.getElementById("sIdiv");
        first.style.position='absolute';
        second.style.position='absolute';
        
        var timer = setInterval(
            function(){
                if(first.style.left=='440px')
                    clearInterval(timer);
            i = i+10;
            first.style.left = i+'px';
            second.style.left = (i+209)+'px';
            },60);    
    }

      js文件中timer是setInterval()返回值,用于作为clearInterval()的参数,来结束循环调用,setInterval()中的function()是循环的语句。

      div的left值在正常赋值是:

    <div style="position:absolute; left:10px"></div>

      因此在重新赋值的时候加上'px'单位。

  • 相关阅读:
    小球掉落
    String当中与转换相关常用的方法有
    字符串的截取方法
    golang 管道
    golang--协程之间通信的方式
    golang--goroutine
    go 时间操作
    吉格勒定理
    检视阅读
    git branch -a发现分支显示不全
  • 原文地址:https://www.cnblogs.com/heyuheitong/p/3996411.html
Copyright © 2011-2022 走看看