Animation frame wrapper.
var frame = require('newtonjs-frame');
var animate, id;
(animate = function (time) {
// Render the current frame...
// ...then request the next one
id = frame.request(animate);
})({});
if (/* Some condition */) {
frame.cancel(id);
}The time argument passed to the callback is much more
useful than the one given directly by requestAnimationFrame.
var frame = require('newtonjs-frame');
frame.request(function (time) {
console.log(time.now); // Timestamp of current
console.log(time.last); // Timestamp of last
console.log(time.start); // Timestamp of start
console.log(time.delta); // Milliseconds since last
console.log(time.progress); // Milliseconds since start
});If you merely require a polyfill for requestAnimationFrame, you might find
newtonjs/raf better suits your needs.
This library isn't available from the NPM repository or any other
package manager, but you can still add it to your package.json
{
"dependencies": {
"newtonjs-frame": "git://github.com/newtonjs/frame.git#master"
}
}We accept contributions to the source via Pull Request, but you must run the tests and compile the JavaScript before it will be considered for merge. The source for this library is written in CoffeeScript, but it is distributed with the compiled JavaScript.
$ npm test # Run tests
$ npm run-script compile # Compile JavaScriptThe content of this library is released under the MIT License by Andrew Lawson.
You can find a copy of this license at http://www.opensource.org/licenses/mit
