div Simple Horizontal Move effect

Source: Internet
Author: User

Place the IMG in the Div, move the div to achieve the effect of moving the IMG, the following is the horizontal movement.

HTML file:

<Divstyle= "float:left; width:1000px">    <Divstyle= "position:absolute; left:10px; float:left; width:250px"ID= "Fidiv">        <imgID= "Firstimg"src= "Images/sjz1." JPG " />    </Div>    <Divstyle= "position:absolute; left:220px; float:left; width:250px"ID= "Sidiv">        <imgID= "Secondimg"src= "Images/sjz2.jpg" />    </Div></Div>

JS file:

vari=10;functiontransferimages () {varFirst = document.getElementById ("Fidiv"); varSecond = document.getElementById ("Sidiv"); First.style.position= ' absolute '; Second.style.position= ' absolute '; varTimer =SetInterval (function(){            if(first.style.left== ' 440px ') clearinterval (timer); I= i+10; First.style.left= i+ ' px '; Second.style.left= (i+209) + ' px '; },60); }

The timer in the JS file is the setinterval () return value, used as a parameter to Clearinterval () to end the loop call, and function () in SetInterval () is a loop statement.

The left value of the div is assigned in the normal value:

<style= "Position:absolute; left:10px"></Div  >

So add the ' px ' unit when you re-assign the value.

Div Simple horizontal move effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.