0.1.0 • Published 9 years ago

request-animation-loop v0.1.0

Weekly downloads
4
License
ISC
Repository
github
Last release
9 years ago

request-animation-loop

setInterval is to setTimeout as requestAnimationLoop is to requestAnimationFrame.

npm version Build Status

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.