JSFiddle - React, Tailwind, and code Playground
CSS
#a {
width: 20px;
height: 20px;
position: absolute;
border: 1px solid;
top: 0;
left: 0;
}
JavaScript
function animate(object, property, start_value, end_value, time) {
var frame_rate = 0.06; // 60 FPS
var frame = 0;
var delta = (end_value - start_value) / time / frame_rate;
console.log(delta);
console.log(start_value);
var handle = setInterval(function() {
frame++;
var value = start_value + delta * frame;
// console.log(value);
object.style[property] = value + "px";
if (value == end_value) {
clearInterval(handle);
}
}, 1 / frame_rate);
}
animate(document.getElementById("a"),
"top",
0,
100,
1000
);