JSFiddle - React, Tailwind, and code Playground
by Ishank Dubey
HTML
<div id="aDiv" style="width:200px;height:100px;background-color:blue;">Test</div>
JavaScript
var myReq, start;
function step(timestamp){
if(!start)start = timestamp;
document.getElementById("aDiv").style.width = (parseInt(document.getElementById("aDiv").style.width,10)-05)+"px";
if(parseInt(document.getElementById("aDiv").style.width,10)< 50 ||
(timestamp - start) > 4000
){
window.cancelAnimationFrame(myReq);
}else
myReq = requestAnimationFrame(step);
}
window.requestAnimationFrame(step);