delay
delay
is a setTimeout
alternative that's locked to Motion's animation frame loop.
This can help synchronise callbacks with other animations, and avoid the overhead of setting many setTimeout
s.
Usage
Import delay
from Motion.
Delay a callback
Pass a callback and duration (measured in seconds) to delay
. The callback will fire on the next animation frame after this duration.
Cancel
delay
returns a function that, when called, will cancel the delay.
Animation loop
delay
fires its callback on the first step of Motion's animation loop, the read
step.
We can therefore batch reads and writes with the rest of the loop using frame
.
Motion is open source. Sponsorships keep the project sustainable.
Every sponsor receives access to our private Discord, and an exclusive mobile and desktop wallpaper pack.