setInterval is to setTimeout as requestAnimationLoop is to requestAnimationFrame.
npm install request-animation-loop --save
Rotate an element for 1 second.
var deg = 0;
var id = requestAnimationLoop(function (deltaTime) {
deg += deltaTime * 0.1;
el.style.transform = "rotate(" + deg + "deg)";
});
setTimeout(function () {
cancelAnimationLoop(id);
}, 1000);
Start an animation loop with function callback
which recieves a time in
milliseconds since last iteration as deltaTime
and id
which is the id
of the loop.
Stop animation loop with id id
.