19th May 2021, 2:02 AM
Harshit Joshi
Harshit Joshi - avatar
3 ответов
+ 3
window.onload = function(){ var pos=0; //starting position var box=document.getElementById("box"); var t=setInterval(move,10); function move(){ if (pos>=150){ clearInterval(t); } else{ pos+=1; box.style.left= pos+ "px"; //px is pixels } } }
19th May 2021, 2:26 AM
Ayush Kumar
Ayush Kumar - avatar
+ 1
Dont run the javascript until the document is loaded therefore add your javascript in onload function. window.onload = function(){ // your js code }
19th May 2021, 2:08 AM
Ayush Kumar
Ayush Kumar - avatar
0
Could you post your code after solving please?
19th May 2021, 2:23 AM
Harshit Joshi
Harshit Joshi - avatar