Core API
delay
A node that introduces a pause in an animation sequence.
The delay function is a simple utility node that creates a pause in an animation. It is a declarative and readable way to create a delay within a sequence.
Example
import * as a from "@freestylejs/ani-core";
// 1. Define an animation that fades in, waits, and then moves.
const myAnimation = a.sequence([
a.ani({ to: { opacity: 1, x: 0 }, duration: 0.5 }),
a.delay(1), // 2. Wait for 1 second.
a.ani({ to: { opacity: 1, x: 100 }, duration: 1 }),
]);
// 3. Create and play the timeline.
const myTimeline = a.rafTimeline(myAnimation);
myTimeline.play({ from: { opacity: 0, x: 0 } });Usage & Concepts
Overview
delay is a simple utility node that does nothing for a specified duration. Its primary purpose is to insert pauses within a sequence composition. It is a "leaf" node, similar to ani, but it does not affect any values.
A delay holds every property for its duration, in record and array timelines alike. The values stay where the previous segment left them.
duration must be a finite number >= 0 (seconds).
Best Practices
- Do use
delayinside asequenceto create a pause between two animations. - Do use
delayat the start of a branch of aparallelblock to offset that branch. - Don't expect
delayinside aparallelblock to pause the other branches. It only extends the total duration of the block when it is the longest item. A trailingdelaycounts toward the duration.
API Reference
| Name | Type | Description |
|---|---|---|
duration | number | Seconds, finite and >= 0. |
options.id | string | (Optional) Identifier of the node: a.delay(seconds, { id }). A string or any extra argument throws a TypeError. |
Related Components
sequence- The primary composition wheredelayis used.