A simple script with a few niceties that allows for multiple requestAnimationFrame calls, and FPS pinning.
The script polyfills rAF if required, then overloads requestAnimationFrame and cancelAnimationFrame with a process that allows multiple frames to be queued up for rAF to run.
This is useful if there are multiple animations running on the page, you want all the callbacks to happen at once, and not on multiple rAF calls. This script is meant as a drop-in solution to that problem.
By default it will overload the original requestAnimationFrame methods, but if you remove the two arguments at the end of the script (or change them) it will introduce window.raf (or what you've named the request & cancel functions).
requestAnimationFrame(fn): can be called multiple times at once, and the queue will only be cleared when the real rAF callback firesrequestAnimationFrame.cancel: helper tocancelAnimationFrame- returnstrueif a handler was due to fire.requestAnimationFrame.fps(fn, fps): helper to pin you function to run every N frames per second.fpsis not milliseconds. Note that this is more akin tosetIntervalthan rAF, as it will reschedule your function to run every N frames.requestAnimationFrame.running: boolean flag to pause all rAF calls - set tofalseand animations will stop, set totrueand they'll resume.
Is this a workaround for this question ?