preemptive-animation-frame

0.1.0 • Public • Published

preemptive-animation-frame

travis npm downloads js-standard-style

Library provides same API as window.requestAnimationFrame but in contrast it is preemptive. It is possible to drop a frame if window.requestAnimationFrame is called (after you've done handling of the current frame) too late. This library helps you avoid such frames drops by wrapping native API and scheduling request ahead of time.

It is especially useful when working with high level abstractions that require you to schedule requests at the end update step.

Install

npm install preemptive-animation-frame

API

const PAF = require('preemptive-animation-frame')
 
// schedule
const requestID = PAF.requestAnimationFrame(time => {
  // repaint
})
 
// cancel
PAF.cancelAnimationFrame(requestID)

Unstable API

You can force animation frame to fire at your demand with forceAnimationFrame

PAF.forceAnimationFrame()

Library internally uses performance.now() polyfill, if you use it in conjunction with this library consider using exported now function to have consistent starting point for produced timestamps.

PAF.now()

Package Sidebar

Install

npm i preemptive-animation-frame

Weekly Downloads

1

Version

0.1.0

License

MPL-2.0

Last publish

Collaborators

  • gozala