Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
requestAnimationFrame
JavaScript
Branch: master
Failed to load latest commit information.
.gitignore Initial commit
History.md 1.2.0
Makefile Initial commit
Readme.md add .cancel(id)
component.json 1.2.0
example.html Initial commit
index.js Removing redundant prefixes.
package.json 1.2.0

Readme.md

raf

request animation frame

Installation

$ component install component/raf

Example

Request the animation frame with raf(fn), cancel with raf.cancel(id).

var x = 0;
var y = 50;
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
var raf = require('raf');

function animate() {
  raf(animate);
  draw();
}

var prev = Date.now();
function draw() {
  var curr = Date.now();
  var diff = curr - prev;
  var p = diff / 16;
  ctx.clearRect(0, 0, 900, 300);
  ctx.beginPath();
  ctx.globalAlpha = .5;
  ctx.arc(x, y, 10, 0, Math.PI * 2, false);
  ctx.fill();
  x += 2;
  y += Math.sin(x/20) * 5;
  prev = curr;
}

animate();

License

MIT

Something went wrong with that request. Please try again.