0.1.0 • Published 9 years ago

request-animation-frame-shim v0.1.0

Weekly downloads
10
License
MIT
Repository
github
Last release
9 years ago

request-animation-frame-shim

This shim doesn't implement any fallback for old browsers. Polyfilling features are limited to support prefixes (module exports requestAnimationFrame, webkitRequestAnimationFrame or mozRequestAnimationFrame, depending which one is available). The key concept of using this shim is to use those functions not directly from global context and be able to mock them during testing (see request-animation-frame-mock).

You can use it with ES6 transpilers like Babel.

import { requestAnimationFrame, cancelAnimationFrame } from 'request-animation-frame-shim';

let frameRequest = requestAnimationFrame(function frameHandler(time) {
    // do your animation step or whatever you want to

    frameRequest = requestAnimationFrame(frameHandler);
});

cancelAnimationFrame(frameRequest);

As well as with standard JavaScript.

var requestAnimationFrame = require('request-animation-frame-shim').requestAnimationFrame;
var cancelAnimationFrame = require('request-animation-frame-shim').cancelAnimationFrame;

var frameRequest = requestAnimationFrame(function frameHandler(time) {
    // do your animation step or whatever you want to

    frameRequest = requestAnimationFrame(frameHandler);
});

cancelAnimationFrame(frameRequest);