+ 1

Why is javascript animation not working properly with the DOM?

when you use animation with other logics, it doesn't work fine with the DOM objects.

9th Feb 2019, 1:23 AM
Ebuka Nzeanochieh
Ebuka Nzeanochieh - avatar
4 Answers
+ 7
You will need a little bit of css for positioning the box. You need to set its position relative. https://code.sololearn.com/Wlh16tR39VnR/?ref=app
9th Feb 2019, 2:05 AM
Arushi Singhania
Arushi Singhania - avatar
+ 4
With other logics : I am unable to understand this. Can u share the code in which u have problem ??
9th Feb 2019, 1:26 AM
Arushi Singhania
Arushi Singhania - avatar
0
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <div id="container"> <div id="box"> </div> </div> <script> window.onload = function() { var pos = 0; //our box element 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'; } } }; </script> </body> </html>
9th Feb 2019, 1:58 AM
Ebuka Nzeanochieh
Ebuka Nzeanochieh - avatar
0
am trying to make the box move left, right, up and down the container but it refuse
9th Feb 2019, 1:59 AM
Ebuka Nzeanochieh
Ebuka Nzeanochieh - avatar