0

How can I make this such that the red box moves on clicking the start button?

I tried this code but it moves anyways. https://code.sololearn.com/W37DR9Mvkk6s/?ref=app

8th Jul 2020, 5:21 AM
Bishal Biswal
Bishal Biswal - avatar
2 Antworten
+ 1
Change your code like this HTML <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <div id="container"> <div id="box"> </div></div> <button id="demo" onclick="start()">Start</button> </body> </html> //Javaacript function start() { //our box element var pos=0; var box = document.getElementById('box'); var t = setInterval(myFunction, 10); var btn = document.getElementById("demo"); function myFunction() { if(pos >= 150) { clearInterval(t); } else { pos += 1; box.style.left = pos+'px'; } } };
8th Jul 2020, 5:29 AM
Shobhith J B
Shobhith J B - avatar
+ 1
8th Jul 2020, 5:54 AM
Bishal Biswal
Bishal Biswal - avatar