OptionalrafLoop: Function
Optional function to be called on each request animation frame.
Gets the current frame rate that raf is running at. Useful for debugging.
Gets the delta in ms between the last executed raf update.
Whether to acquire the delta time in seconds. Defaults to ms.
Gets the elasped time since raf started.
Gets the time (Date) when raf started.
Sets a function to execute on each raf loop. If the condition resolves to true, the raf loop callbacks will be executed. If false, the raf loop is culled.
Allows you to pass an option to tell this raf to execute only when the given element is in the viewport. Optionally pass intersection observer options.
Note that this still requires you to start the raf. You can do this with the promise that the method returns (resolved when ev is ready) or at a later time.
Note it's recommended that you add a rootMargin to your ev settings if need to do offscreen processing.
var raf = new Raf(()=> {
...
})
// Set element and run when it's ready.
raf.runWhenElementIsInview(
document.getElementById("myelement"),
{
rootMargin: '300px 0px 300px 0px'
}
).then(()=> {
raf.start();
})
OptionalintersectionObserverOptions: ObjectSets the fps .
Sets the read write mode.
Starts the RAF animation loop.
Stops the RAF animation loop.
Removes a progress listener.
Adds a raf listener
A class that creates a RAF loop and calls a specific callback. Setting the frame rate will throttle the animation.
Example usage;
RunWhen option. You can pass a run condition to limit raf only when the condition resolve to true. This is useful to cull unncessary requests. An example is to use elementVisility to only run RAF when an element is in view and stop raf when it goes out of view.
// Runs only when myElement is in view. // Option 2: You can use runWhenElementIsInview option.
Batch read / write.
Batch write / read. To batch write and read, wrap your methods in read and write calls. Read / Write calls uses the degu raf registry so your reads or writes can get delayed by one raf cycle.
You can also create a read / write only raf by passing no rafLoop to the constructor.
If you want read / writes to NOT cull, you can set the read write mode. This is needed if you pass a rafLoop to the constructor but additionally, want to use the read write outside your loop even when your raf is stopped.
No Inherit Doc