UNPKG

1.17 kBMarkdownView Raw
1# raf
2
3[![browser support](http://ci.testling.com/chrisdickinson/raf.png)](http://ci.testling.com/chrisdickinson/raf)
4
5reqeustAnimationFrame polyfill for browserify.
6
7```javascript
8var raf = require('raf')
9 , canvas = document.getElementById('opengl')
10
11raf(canvas)
12 .on('data', function(dt) {
13 console.log('difference in time is '+dt+'ms')
14 })
15
16
17```
18
19# API
20
21## raf([optional element], [optional tick function]) -> event emitter
22
23returns a event emitter that immediately starts emitting 'data'
24events representing animation frames for a given element (or for the entire
25window, if no element is passed).
26
27if you pass a function as the first or second argument it will get called on every tick. this is a convenience method for
28the example above that binds to the `data` event, e.g. `raf().on('data', tickFunction)` is the same as `raf(tickFunction)`
29or `raf(el, tickFunction)`
30
31## ee.pause() / ee.resume()
32
33pauses or resumes the events coming out of `ee`.
34
35the `dt` on the next event after a resume will represent the difference between
36the last rendered frame and the newest frame.
37
38## raf.polyfill
39
40the polyfilled `requestAnimationFrame` function.
41
42# license
43
44MIT
45