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