Guides · 06

Timelines

Run many tracks from one seekable clock: play, pause, seek, reverse and change the rate.

Tracks on one clock

useTimeline(tracks, options, deps) creates a timeline owned by the component. Each track is a list of keyframes, or { values, times, at, duration } with at and duration in milliseconds.

progress is one CSS variable, and numeric or length tracks are calc() expressions of it, so a timeline in ordinary style writes one variable per frame.

Preparing the example…

Playback control

play({ from, rate }), pause(), seek(ms) and reverse() control the clock. state, currentTime, duration and the finished promise describe it. repeat and repeatDelay loop it.

Title.jsx
const intro = useTimeline(
  {
    y: ['24px', '0px'],
    fade: { values: [0, 1], at: 0, duration: 300 },
    line: { values: [0, 1], at: 200, duration: 600 },
  },
  { duration: 800 },
);

intro.seek(400); // milliseconds
intro.play({ rate: 0.5 });
intro.reverse();

Outside React

createTimeline is the same clock without a component. Call dispose() when you are done.

Search

Type to search the documentation.