JSFiddle - React, Tailwind, and code Playground

by Arthur Lutkevichus

HTML

<div id="asd">

</div>

CSS

#asd {
  background: red;
  width: 10px;
  height: 10px;
  position: relative;
  left: 150px;
}

JavaScript

var start = null;
var element = document.getElementById('asd');

function step(timestamp) {
  if (!start) start = timestamp;
  var progress = timestamp - start;
  element.style.left = (parseInt(window.getComputedStyle(element).left) - 1) + 'px';

  if (parseInt(element.style.left) < -element.offsetWidth) {
    element.style.left = '150px';
  }

  window.requestAnimationFrame(step);
}

window.requestAnimationFrame(step);