raf-component
request animation frame
Last updated 11 years ago by tjholowaychuk .
Repository · Bugs · Original npm · Tarball · package.json
$ npm install raf-component 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.2                                ...           latest (11 years ago)

5 Versions

  • 1.1.2                                ...           11 years ago
  • 1.1.1                                ...           11 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.0                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Total 6
Today 1
This Week 1
This Month 3
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE