raf
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
performance-now | 2.1.0 | 4.46 kB | MIT | prod |
raf
, also known as requestAnimationFrame
, is a polyfill for both node.js and the browser. It provides a simple and streamlined way to create smooth and efficient animations by telling the browser to execute specific coding instructions before the next repaint. This way, the browser can efficiently manage resources and provide a great user experience.
Using raf
is pretty straightforward. It can be integrated with common module bundlers or directly included using a script tag. Here's how to use raf
:
Firstly, install the raf
package from npm:
npm install --save raf
Then, require it like any other module:
const raf = require('raf')
To create an animation loop, just call raf()
with the desired function as a callback:
raf(function tick() {
// Animation logic goes here
raf(tick)
})
If you need to cancel the scheduled animation, simply use the cancel
method and provide the identifier returned by raf()
:
var handle = raf(callback) // schedule the animation
raf.cancel(handle) // cancels the scheduled animation
You can also easily polyfill window.requestAnimationFrame
and window.cancelAnimationFrame
using the polyfill
method:
raf.polyfill()
The raf
package's documentation can be found at the Mozilla Developer Network and W3 Specification, using the following links:
For in-depth information and guidance, these resources provide comprehensive details about the requestAnimationFrame
API.