+ 1
How to keep box animating forever?
So I'm trying to animate a box. I got till how to animate it to the right but it stops there. I want it to now go to the left and then to the right and loop like that. What should I add to my code for it to do that? Here's my existing code : var pos = 0; 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"; _____________ Thank you.
5 Respuestas
+ 1
AravindR2006 instead of writing clear interval in if try to write pos = 0;
+ 2
That works, thank you Krish !
0
Please share your code file for more specifications
0
AravindR2006 thanks 😊😊