Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

raf-component

component8061.1.2

request animation frame

animate, requestAnimationFrame, performance

readme

raf

request animation frame

Installation

$ component install component/raf

Example

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

changelog

1.1.2 / 2013-07-12

  • fix .cancel() with fallback #4 @ilsken

1.1.1 / 2013-07-12

  • fix .cancel(), bitches when window is not the receiver...

1.1.0 / 2013-07-12

  • add .cancel(id)