JSFiddle - React, Tailwind, and code Playground

HTML

<div id="box"></div>

CSS

#box {
    position:absolute;
    width:50px;
    height:50px;
    left:0;
    top:0;
    background: #F00;
}

JavaScript

function setPosition(el, x, y) {
    var style = window.getComputedStyle(el);
    el.style.left = parseInt(style.left) + x + "px";
    el.style.top = parseInt(style.top) + y + "px";
}

var sX = window.screenX,
    sY = window.screenY,
    box = document.getElementById("box");

var interval = setInterval(function() {
    if (window.screenX !== sX || window.screenY !== sY) {
        setPosition(box, sX - window.screenX, sY - window.screenY);
        sX = window.screenX;
        sY = window.screenY;
    }
}, 1000/30);