JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div id="loader06"></div>
</body>
CSS
#loader06 {
height: 40px;
width: 40px;
background-color: blue;
position: relative;
}
JavaScript
Prep6();
function Prep6() {
window_Height = window.innerHeight;
window_Width = window.innerWidth;
image_Element = document.getElementById("loader06");
image_Height = image_Element.clientHeight;
image_Width = image_Element.clientWidth;
availSpace_V = window_Height - image_Height;
availSpace_H = window_Width - image_Width;
var changeInterval = 2000;
setInterval(function () {
moveImage6(availSpace_V, availSpace_H, image_Element);
}, changeInterval);
}
function moveImage6(availSpace_V, availSpace_H, image_Element) {
var randNum_V = Math.round(Math.random() * availSpace_V);
var randNum_H = Math.round(Math.random() * availSpace_H);
image_Element.style.top = randNum_V + "px";
image_Element.style.left = randNum_H + "px";
}