Ani
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 delay inside a sequence to create a pause between two animations.
  • Do use delay at the start of a branch of a parallel block to offset that branch.
  • Don't expect delay inside a parallel block to pause the other branches. It only extends the total duration of the block when it is the longest item. A trailing delay counts toward the duration.

API Reference

NameTypeDescription
durationnumberSeconds, finite and >= 0.
options.idstring(Optional) Identifier of the node: a.delay(seconds, { id }). A string or any extra argument throws a TypeError.
  • sequence - The primary composition where delay is used.