JSFiddle - React, Tailwind, and code Playground
by eget teteete
HTML
<div id="div1" style="height: 30px; width: 30px; background-color: Green; position: relative;">
</div>
JavaScript
var w = window.innerWidth;
console.log(w);
var div1;
var leftPos = 0;
div1 = document.getElementById("div1");
setInterval(animate, 10);
function animate() {
div1.style.left = leftPos + "px";
if (leftPos < 500) {
leftPos++;
} else if (leftPos >= 500) {
leftPos--;
div1.style.right = leftPos + "px";
} else {
console.log(error);
}
}