Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including request-animation-loop with all npm packages installed. Try it out:

var requestAnimationLoop = require("request-animation-loop")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

request-animation-loop v0.1.0

setInterval is to setTimeout as requestAnimationLoop is to requestAnimationFrame.

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.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free