$npx -y skills add greensock/gsap-skills --skill gsap-timelineOfficial GSAP skill for timelines — gsap.timeline(), position parameter, nesting, playback. Use when sequencing animations, choreographing keyframes, or when the user asks about animation sequencing, timelines, or animation order (in GSAP or when recommending a library that suppo
| 1 | # GSAP Timeline |
| 2 | |
| 3 | ## When to Use This Skill |
| 4 | |
| 5 | Apply when building multi-step animations, coordinating several tweens in sequence or parallel, or when the user asks about timelines, sequencing, or keyframe-style animation in GSAP. |
| 6 | |
| 7 | **Related skills:** For single tweens and eases use **gsap-core**; for scroll-driven timelines use **gsap-scrolltrigger**; for React use **gsap-react**. |
| 8 | |
| 9 | ## Creating a Timeline |
| 10 | |
| 11 | ```javascript |
| 12 | const tl = gsap.timeline(); |
| 13 | tl.to(".a", { x: 100, duration: 1 }) |
| 14 | .to(".b", { y: 50, duration: 0.5 }) |
| 15 | .to(".c", { opacity: 0, duration: 0.3 }); |
| 16 | ``` |
| 17 | |
| 18 | By default, tweens are **appended** one after another. Use the **position parameter** to place tweens at specific times or relative to other tweens. |
| 19 | |
| 20 | ## Position Parameter |
| 21 | |
| 22 | Third argument (or position property in vars) controls placement: |
| 23 | |
| 24 | - **Absolute**: `1` — start at 1 second. |
| 25 | - **Relative (default)**: `"+=0.5"` — 0.5s after end; `"-=0.2"` — 0.2s before end. |
| 26 | - **Label**: `"labelName"` — at that label; `"labelName+=0.3"` — 0.3s after label. |
| 27 | - **Placement**: `"<"` — start when recently-added animation starts; `">"` — start when recently-added animation ends (default); `"<0.2"` — 0.2s after recently-added animation start. |
| 28 | |
| 29 | Examples: |
| 30 | |
| 31 | ```javascript |
| 32 | tl.to(".a", { x: 100 }, 0); // at 0 |
| 33 | tl.to(".b", { y: 50 }, "+=0.5"); // 0.5s after last end |
| 34 | tl.to(".c", { opacity: 0 }, "<"); // same start as previous |
| 35 | tl.to(".d", { scale: 2 }, "<0.2"); // 0.2s after previous start |
| 36 | ``` |
| 37 | |
| 38 | ## Timeline Defaults |
| 39 | |
| 40 | Pass defaults into the timeline so all child tweens inherit: |
| 41 | |
| 42 | ```javascript |
| 43 | const tl = gsap.timeline({ defaults: { duration: 0.5, ease: "power2.out" } }); |
| 44 | tl.to(".a", { x: 100 }).to(".b", { y: 50 }); // both use 0.5s and power2.out |
| 45 | ``` |
| 46 | |
| 47 | ## Timeline Options (constructor) |
| 48 | |
| 49 | - **paused: true** — create paused; call `.play()` to start. |
| 50 | - **repeat**, **yoyo** — same as tweens; apply to whole timeline. |
| 51 | - **onComplete**, **onStart**, **onUpdate** — timeline-level callbacks. |
| 52 | - **defaults** — vars merged into every child tween. |
| 53 | |
| 54 | ## Labels |
| 55 | |
| 56 | Add and use labels for readable, maintainable sequencing: |
| 57 | |
| 58 | ```javascript |
| 59 | tl.addLabel("intro", 0); |
| 60 | tl.to(".a", { x: 100 }, "intro"); |
| 61 | tl.addLabel("outro", "+=0.5"); |
| 62 | tl.to(".b", { opacity: 0 }, "outro"); |
| 63 | tl.play("outro"); // start from "outro" |
| 64 | tl.tweenFromTo("intro", "outro"); // pauses the timeline and returns a new Tween that animates the timeline's playhead from intro to outro with no ease. |
| 65 | ``` |
| 66 | |
| 67 | ## Nesting Timelines |
| 68 | |
| 69 | Timelines can contain other timelines. |
| 70 | |
| 71 | ```javascript |
| 72 | const master = gsap.timeline(); |
| 73 | const child = gsap.timeline(); |
| 74 | child.to(".a", { x: 100 }).to(".b", { y: 50 }); |
| 75 | master.add(child, 0); |
| 76 | master.to(".c", { opacity: 0 }, "+=0.2"); |
| 77 | ``` |
| 78 | |
| 79 | ## Controlling Playback |
| 80 | |
| 81 | - **tl.play()** / **tl.pause()** |
| 82 | - **tl.reverse()** / **tl.progress(1)** then **tl.reverse()** |
| 83 | - **tl.restart()** — from start. |
| 84 | - **tl.time(2)** — seek to 2 seconds. |
| 85 | - **tl.progress(0.5)** — seek to 50%. |
| 86 | - **tl.kill()** — kill timeline and (by default) its children. |
| 87 | |
| 88 | ## Official GSAP Best practices |
| 89 | |
| 90 | - ✅ Prefer timelines for sequencing |
| 91 | - ✅ Use the **position parameter** (third argument) to place tweens at specific times or relative to labels. |
| 92 | - ✅ Add **labels** with `addLabel()` for readable, maintainable sequencing. |
| 93 | - ✅ Pass **defaults** into the timeline constructor so child tweens inherit duration, ease, etc. |
| 94 | - ✅ Put ScrollTrigger on the timeline (or top-level tween), not on tweens inside a timeline. |
| 95 | |
| 96 | ## Do Not |
| 97 | |
| 98 | - ❌ Chain animations with **delay** when a **timeline** can sequence them; prefer `gsap.timeline()` and the position parameter for multi-step animation. |
| 99 | - ❌ Forget to pass **defaults** (e.g. `defaults: { duration: 0.5, ease: "power2.out" }`) when many child tweens share the same duration or ease. |
| 100 | - ❌ Forget that **duration** on the timeline constructor is not the same as tween duration; timeline “duration” is determined by its children. |
| 101 | - ❌ Nest animations that contain a ScrollTrigger; ScrollTriggers should only be on top-level Tweens/Timelines. |