Giter Site home page Giter Site logo

raf's Introduction

raf

Browser Support

requestAnimationFrame polyfill for node and the browser.

var raf = require('raf')

raf(function tick() {
  // Animation logic
  raf(tick)
})

Note: The stream/event emitter logic found in versions prior to 1.0.0 can be found in raf-stream.

Getting started

CommonJS (Node, Browserify, Webpack, etc.)

Install raf from npm:

npm install --save raf

Require it like you would any other module:

const raf = require('raf')

AMD (require.js, etc)

Download the UMD-bundle from wzrd.in (remember to include the current version number in the filename).

Add it to your AMD module loader config and require it like you would any other module:

define(['raf'], raf => {...})

<script>

Download the UMD-bundle from wzrd.in (remember to include the current version number in the filename).

Then include it via a script tag:

<script src="raf-x.x.x.js"></script>

The API will be available on window.raf.

API

Documentation at Mozilla Developer Network, W3 Specification

var handle = raf(callback)

callback is the function to invoke in the next frame. handle is a long integer value that uniquely identifies the entry in the callback list. This is a non-zero value, but you may not make any other assumptions about its value.

raf.cancel(handle)

handle is the entry identifier returned by raf(). Removes the queued animation frame callback (other queued callbacks will still be invoked unless cancelled).

raf.polyfill()

Shorthand to polyfill window.requestAnimationFrame and window.cancelAnimationFrame if necessary (Polyfills global in node).

Alternatively you can require raf/polyfill which will act the same as require('raf').polyfill().

Acknowledgments

Based on work by Erik Möller, Paul Irish, and Tino Zijdel (https://gist.github.com/paulirish/1579671)

License

MIT

raf's People

Contributors

cmtegner avatar chrisdickinson avatar raynos avatar caseywebb avatar ljharb avatar iclanzan avatar devinrhode2 avatar dylanpiercey avatar hughsk avatar max-mapper avatar tombyrer avatar

Watchers

James Cloos avatar Travis Clarke avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.