0.1.0 • Published 9 years ago
preemptive-animation-frame v0.1.0
preemptive-animation-frame
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()