Here I am defining the div template to move, the code is as follows:
1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title></title>6<style type= "Text/css" >7 #div1 {8 width:200px;9 height:200px;Tenbackground-color:red; One } A</style> - -<body> the<div id= "Div1" style= "position:relative;left:200px" > -</div> -<script type= "Text/javascript" > - varNum=document.getelementbyid ("Div1") + //the initial value of the DIV block - varnums=200; + //Loop move, move once every 0.5 seconds A varTestinterval=setinterval (fun,500) at functionFun () { - //set a New left value -Num.setattribute ("Style", "Position:relative;left:" +nums+ ' px ') - //10px per move -nums+=10; - //Stop Moving when you're left:1110px. in if(nums==1110){ - clearinterval (testinterval); to } + } -</script> the</body> *
SetAttribute can only operate on row properties, and other properties are not accessible.
JavaScript control loop Move template