+ 2

How can I create a moving animation element using JavaScript

18th May 2020, 2:05 AM
Elvis Nestory
Elvis Nestory - avatar
2 Respuestas
+ 1
This code is from sololearn <!DOCTYPE html> <html> <head> <title>Page Title</title> <style> #container { width: 200px; height: 200px; background: green; position: relative; } #box { width: 50px; height: 50px; background: red; position: absolute; } </style> <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> </head> <body> <div id="container"> <div id="box"> </div> </div> </body> </html> This will create a moving animation. Or just visit 👇👇👇👇 https://www.sololearn.com/learn/JavaScript/2756/ Hope this will help
18th May 2020, 2:22 AM
Ayush Pandey
Ayush Pandey - avatar
+ 1
CSS animations might help here too.
18th May 2020, 3:55 PM
Nathaniel Levin
Nathaniel Levin - avatar