I've been searching for a solution to make a div slide to the side after 2 seconds using JavaScript, but I haven't found one that quite fits what I'm looking for. Here's my current code:
setTimeout("slide()", 1000)
function slide() {
var myElement = document.querySelector("#box");
myElement.style.left = 200px;
setTimeout("slide()", 2000)
};
#box {
position: absolute;
left: 100px;
top: 100px;
width: 300px;
height: 300px;
background: blue;
}
<div id="box">box</div>
If there's anything wrong with my approach or if you can point me in the right direction with a helpful resource, it would be greatly appreciated! Thanks