JSFiddle - React, Tailwind, and code Playground

HTML

<div id="echo"></div>

<div id="layer2"></div>

CSS

#layer2 {
    position: absolute; background: #33FFCC;
    top: 100px;     left: 100px;
    width: 20px;    height: 20px;
}

JavaScript

var CoordObj = layer2.getBoundingClientRect();
Top = CoordObj.top;
Left = CoordObj.left;
	
var timerId = setInterval(function() {
  angle = 45;
  Top -= Math.sin(angle * Math.PI / 180);
  Left -= Math.cos(angle * Math.PI / 180);
  layer2.style.top = Top+'px';
  layer2.style.left = Left+'px';
}, 30);


// остановить повторы
setTimeout(function() {
  clearInterval(timerId);
  //alert( 'стоп' );
  document.getElementById('echo').innerHTML='стоп';
}, 11000);