You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.4 KiB

3 jaren geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # raf
  2. [![Browser Support](http://ci.testling.com/chrisdickinson/raf.png)](http://ci.testling.com/chrisdickinson/raf)
  3. requestAnimationFrame polyfill for node and the browser.
  4. ```js
  5. var raf = require('raf')
  6. raf(function tick() {
  7. // Animation logic
  8. raf(tick)
  9. })
  10. ```
  11. **Note:** The stream/event emitter logic found in versions prior to 1.0.0 can be found in [raf-stream](https://www.npmjs.org/package/raf-stream).
  12. ## Getting started
  13. ### CommonJS (Node, Browserify, Webpack, etc.)
  14. Install `raf` from npm:
  15. ```bash
  16. npm install --save raf
  17. ```
  18. Require it like you would any other module:
  19. ```js
  20. const raf = require('raf')
  21. ```
  22. ### AMD (require.js, etc)
  23. Download the UMD-bundle from [wzrd.in](https://wzrd.in/standalone/raf@latest) (remember to include the current version number in the filename).
  24. Add it to your AMD module loader config and require it like you would any other module:
  25. ```html
  26. define(['raf'], raf => {...})
  27. ```
  28. ### `<script>`
  29. Download the UMD-bundle from [wzrd.in](https://wzrd.in/standalone/raf@latest) (remember to include the current version number in the filename).
  30. Then include it via a script tag:
  31. ```html
  32. <script src="raf-x.x.x.js"></script>
  33. ```
  34. The API will be available on `window.raf`.
  35. ## API
  36. [Documentation at Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame), [W3 Specification](http://www.w3.org/TR/animation-timing/#requestAnimationFrame)
  37. ### var handle = raf(callback)
  38. `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.
  39. ### raf.cancel(handle)
  40. `handle` is the entry identifier returned by `raf()`. Removes the queued animation frame callback (other queued callbacks will still be invoked unless cancelled).
  41. ### raf.polyfill([object])
  42. Shorthand to polyfill `window.requestAnimationFrame` and `window.cancelAnimationFrame` if necessary (Polyfills `global` in node).
  43. Alternatively you can require `raf/polyfill` which will act the same as `require('raf').polyfill()`.
  44. If you provide `object` the polyfills are attached to that given object, instead of the inferred global.
  45. Useful if you have an instance of a fake `window` object, and want to add `raf` and `caf` to it.
  46. ## Acknowledgments
  47. Based on work by Erik Möller, Paul Irish, and Tino Zijdel (https://gist.github.com/paulirish/1579671)
  48. ## License
  49. MIT