0.1.0 • Published 9 years ago
request-animation-loop v0.1.0
request-animation-loop
setInterval is to setTimeout as requestAnimationLoop is to requestAnimationFrame.
Install
npm install request-animation-loop --save
Example
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);
API
requestAnimationLoop(callback(deltaTime, id))
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.
cancelAnimationLoop(id)
Stop animation loop with id id
.
0.1.0
9 years ago