Transient
A simple and minimal animation loop. Consistent frame rate's are achieved with requestAnimationFrame
and high resolution timing.
This library is great for simple transition animations, thus the name, but can also be used for complex animations.
Usage:
const Animation = const el = document // Create the animationvar fadeIn = duration: 1500 // 1.5 seconds { // progress is an integer between 0 and 1 elstyleopacity = progress; } // Start the animationfadeInstart
Options:
duration
: The animation duration in milliseconds. default:5000
fps
: Consistant frames per second for the animation. default:60
loop
: Should the animation loop? default:false
draw
: The draw function which is called for each loop.onEnd
: A function to call when the animation is finished.onCancel
: A function to call when the animation is canceled. If this is not specified it will call theonEnd
function
Advanced Usage
This package's main export is perfect for handling single animations, but it also exports a loop for more complex work. A single
loop can be started for general animation use, and many Transient
animation instances can be attached to one loop. Here is an example:
const Animation = const Loop = // or const Loop = Animation.Loop // Only use one loop to syncronize the animationsvar l = var moveBackground = duration: 1000 * 10 // 10s animationLoop: l { // Draw background }var moveForeground = duration: 1000 * 5 // 5s animationLoop: l { // Draw foreground } // Start the animationsmoveBackgroundstartmoveForegroundstart