Adding Animations
add()
Adds an animation or timer to the timeline at a specific position.Overload 1: Add Animation
Target elements to animate. Accepts CSS selectors (strings), DOM elements, JavaScript objects, NodeLists, or arrays of these.
Animation parameters including properties to animate and animation options.
Position in the timeline where the animation should be added. See Timeline Position Types for details.
Overload 2: Add Timer
Timer parameters including duration, delay, and callbacks.
Position in the timeline where the timer should be added.
Overload 3: Add with Stagger Function
Function that returns the position for each target element, enabling staggered animations.Signature:
(target, index, length, timeline) => TimelinePositionset()
Instantly sets property values on targets at a specific timeline position (zero-duration animation).Target elements to set properties on.
Properties to set instantly. Duration is automatically set to 0.
Timeline position where values should be set.
The
set() method automatically sets duration: 0 and composition: 'replace', making it ideal for setting initial states or creating instant property changes.sync()
Synchronizes external animations (WAAPI animations, Anime.js instances) with the timeline.The animation to synchronize. Can be an Anime.js Timer/Animation/Timeline, a WAAPI Animation, or a native Animation instance.
Timeline position where the synchronized animation should start.
call()
Executes a callback function at a specific timeline position.Function to execute. Receives the timeline instance as its argument.
Timeline position where the callback should be executed.
label()
Adds a named position label to the timeline for easier positioning of subsequent animations.Name of the label to create.
Timeline position for the label. Defaults to current timeline duration.
Control Methods
remove()
Removes animations for specific targets or properties from the timeline.Target elements whose animations should be removed.
Optional specific property name to remove. If omitted, all animations for the targets are removed.
stretch()
Stretches or compresses the timeline to a new duration, proportionally adjusting all children and labels.New total duration for the timeline in milliseconds.
The
stretch() method proportionally scales:- All child animation durations
- All child animation delays and offsets
- All label positions
- Loop delays
refresh()
Refreshes all child animations in the timeline, recalculating dynamic values and updating target references.revert()
Reverts the timeline to its initial state, seeking to time 0, cancelling playback, and cleaning up inline styles.Inherited Methods from Timer
The Timeline class inherits all control methods from Timer:Playback Control
play()- Starts or resumes playback in forward directionpause()- Pauses playbackresume()- Resumes playback from current positionrestart()- Resets to beginning and starts playingreverse()- Starts or resumes playback in reverse directionalternate()- Alternates playback direction
Seeking
seek(time, muteCallbacks?, internalRender?)- Seeks to a specific time positionreset(softReset?)- Resets the timeline to its initial state
Lifecycle
init(internalRender?)- Initializes the timelinecancel()- Cancels the timeline and removes it from the enginecomplete(muteCallbacks?)- Immediately completes the timeline
Promise Support
then(callback?)- Returns a Promise that resolves when the timeline completes
Timeline Position Types
TheTimelinePosition parameter accepts various formats for positioning animations:
Absolute position in milliseconds from timeline start.Example:
1000 - Places animation at exactly 1000msRelative position after the previous animation ends.Example:
'+=500' - Starts 500ms after previous animationRelative position before the previous animation ends.Example:
'-=200' - Starts 200ms before previous animation endsPosition as a multiplier of total timeline duration.Example:
'*=0.5' - Places at 50% of timeline durationAt the end of the previous animation.Example:
'<' - Starts when previous animation endsAt the start of the previous animation.Example:
'<<' - Starts at same time as previous animationRelative to the start of the previous animation.Example:
'<<+=250' - Starts 250ms after previous animation startsAt a named label position.Example:
'myLabel' or 'myLabel+=500'See Also
- Timeline Class - Timeline constructor and properties
- Timeline Parameters - Detailed parameter reference