div簡單水平移動效果

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   檔案   sp   div   

  將img放置在div中,通過移動div達到移動img的效果,下面是水平移動。

  html檔案:

<div style="float:left; width:1000px">    <div style="position:absolute; left:10px; float:left; width:250px" id="fIdiv">        <img id="firstImg" src="images/sjz1.JPG" />    </div>    <div style="position:absolute; left:220px; float:left; width: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‘單位。

div簡單水平移動效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.