timeline
Create complex sequences of animations across multiple elements.
Sequence
The timeline sequence
is an array:
This array accepts animate
definitions:
By default, each animation will play in sequence, one after the other:
at
The timing of each animations can be adjusted with the at
option.
Pass a number to define a specific time:
Pass a number as string starting with +
or -
to start relative to the end of the previous animation:
Or pass "<"
to start at the same time as the previous animation:
Labels
By passing a string in the sequence you can mark that time with a label, to later refer to it with an at
:
In the above example, "my label"
will be set to the 2
second mark. Later in the sequence, you can refer to the 2
second mark in at
by using this label:
Alternatively, a label can be defined absolutely or relatively by passing it as an object with its own `at` property:
Here, "my label"
will be set to the 1.5
second mark.
Forward-filling keyframes
When defining a segment with multiple keyframes, the first keyframe will be forward-filled to the start of the animation.
So in this example, button
elements will be set to opacity: 0
at the very start of the animation, and then begin animating after 0.5
seconds:
Options
duration
Default: Automatically calculated
A duration, in seconds, that the animation will take to complete.
By default, this is automatically calculated by the provided sequence. But if provided explicitly, the whole animation will be scaled to fit this duration.
delay
Default: 0
A duration, in seconds, that the animation will be delayed before starting.
endDelay
Default: 0
A duration, in seconds, that the animation will wait at the end before ending.
direction
Default: "normal"
The direction of animation playback. "normal"
, "reverse"
, "alternate"
, or "alternate-reverse"
.
repeat
Default: 0
The number of times the animation should repeat. Set to Infinity
to repeat indefinitely.
defaultOptions
An object of options to use as the default options
for each animation in the sequence.
Returns
timeline()
returns AnimationControls
.