An element is stationary, causing it to move automatically on the screen.
This is a relatively simple question. I encountered it while studying, so I wrote it down.
<script> <br>var timenum; <br>var mar=0;//Control movement Variable of amount<br>var flag = 0;//A variable to control left and right movement<br>//Function to move to the right<br>function moveright(){ <br>sp1.style.marginLeft=mar " px"; <br>mar=mar 5; <br>} <br>//Function to move to the right<br>function moveleft(){ <br>sp1.style.marginLeft=mar "px"; <br>mar=mar-5; <br>} <br><br>function go() { <br>var sp1 =document.getElementById("sp1"); <br>var btn1 = document.getElementById("start" ); <br>if(!btn1.disabled){ <br>btn1.disabled = true; <br>document.getElementById("pause").disabled=false; <br>} <br>sp1.innerHTML=parseInt (sp1.innerHTML) 1; <br>timenum = window.setTimeout(go,10); <br>if(flag==1){ <br>window.setTimeout(moveleft,10); <br>} <br>if(flag==0){ <br>window.setTimeout(moveright,10); <br>} <br>if(mar>(window.outerWidth)){ <br>flag=1; <br>} <br>if(mar<0){ <BR>flag=0; <BR>} <BR>} <BR>function stop(){ <BR>document.getElementById("start").disabled = false; <BR>document.getElementById("pause").disabled=true; <BR>window.clearTimeout(timenum); <BR>} <BR></script>
< body>