AThevon/genjutsu / skills/_jutsu/gsap
gsap
VerifiedGSAP animation engine sub-skill - core, timeline, ScrollTrigger, plugins.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.1 KB |
| references/core.md | markdown | 7.5 KB |
| references/plugins.md | markdown | 9.0 KB |
| references/scrolltrigger.md | markdown | 7.8 KB |
| references/timeline.md | markdown | 5.5 KB |
references/timeline.md
View on GitHub# GSAP Timeline
## Creation
```js
const tl = gsap.timeline({
defaults: { duration: 0.8, ease: "power2.out" }, // applies to all children
paused: false,
repeat: -1, // -1 = infinite
yoyo: true,
repeatDelay: 0.5,
onComplete: () => console.log("done"),
});
```
## Position Parameter
The position parameter controls WHERE a tween is inserted in the timeline. It's the 3rd argument of `.to()`, `.from()`, `.fromTo()`, `.add()`.
### Absolute values
```js
tl.to(".a", { x: 100 }, 0); // at exactly 0s (start of the timeline)
tl.to(".b", { x: 100 }, 1); // at exactly 1s
tl.to(".c", { x: 100 }, 2.5); // at exactly 2.5s
```
### Relative to the end of the timeline
```js
tl.to(".a", { x: 100 }); // appends to the end
tl.to(".b", { x: 100 }, "+=0.5"); // 0.5s AFTER the end
tl.to(".c", { x: 100 }, "-=0.3"); // 0.3s BEFORE the end (overlap)
```
### Relative to the previous tween
```js
tl.to(".a", { x: 100 });
tl.to(".b", { x: 100 }, "<"); // same start as the previous
tl.to(".c", { x: 100 }, "<0.2"); // 0.2s after the START of the previous
tl.to(".d", { x: 100 }, ">"); // at the END of the previous
tl.to(".e", { x: 100 }, ">-0.1"); // 0.1s BEFORE the end of the previous
```
### With labels
```js
tl.addLabel("intro", 1);
tl.to(".a", { x: 100 }, "intro"); // at the label
tl.to(".b", { x: 100 }, "intro+=0.3"); // 0.3s after the label
```
## Position cheatsheet
```
tl ─────────────────────────────────────>
| A | | B |
| C | | D |
| E |
A: tl.to(a, {}, 0) // absolute
B: tl.to(b, {}) // sequential (end of A)
C: tl.to(c, {}, "<") // start of B
D: tl.to(d, {}, "+=0.5") // 0.5s after end of C
E: tl.to(e, {}, ">-0.2") // 0.2s before end of D
```
## Labels
```js
tl.addLabel("reveal", "+=0.5"); // adds a label at the current position + 0.5s
tl.to(".box", { x: 200 }, "reveal"); // uses the label as position
tl.play("reveal"); // plays from the label
tl.seek("reveal"); // jumps to the label without playing
```
## .add() method
Adds tweens, callbacks, or labels.
```js
tl.add(gsap.to(".a", { x: 100 }), 1); // tween at 1s
tl.add(() => console.log("checkpoint"), "+=0.5"); // callback
tl.add("myLabel"); // label shorthand
```
## Nesting (nested timelines)
Timelines can contain other timelines. Each sub-timeline acts as a single "block" in the parent.
```js
function heroAnimation() {
const tl = gsap.timeline();
tl.from(".hero-title", { y: 50, opacity: 0 })
.from(".hero-subtitle", { y: 30, opacity: 0 }, "<0.2")
.from(".hero-cta", { scale: 0.8, opacity: 0 }, "<0.1");
return tl;
}
function cardsAnimation() {
const tl = gsap.timeline();
tl.from(".card", { y: 40, opacity: 0, stagger: 0.15 });
return tl;
}
// Master timeline
const master = gsap.timeline();
master
.add(heroAnimation())
.add(cardsAnimation(), "-=0.3"); // 0.3s overlap
```
**Advantage**: each section is encapsulated, testable, and repositionable.
## defaults on Timeline
Defaults propagate to direct children but NOT to nested timelines.
```js
const tl = gsap.timeline({
defaults: { duration: 1, ease: "power3.out" },
});
tl.to(".a", { x: 100 }); // duration: 1, ease: power3.out
tl.to(".b", { x: 100, duration: 2 }); // duration: 2 (override), ease: power3.out
// Child timeline: its own defaults apply
const child = gsap.timeline({ defaults: { duration: 0.5 } });
tl.add(child); // the parent's defaults do NOT apply to child's tweens
```
## Controlling the Timeline
```js
tl.play();
tl.pause();
tl.resume();
tl.reverse();
tl.restart();
tl.kill();
// Navigation
tl.seek(2); // jumps to 2s
tl.seek("myLabel"); // jumps to the label
tl.progress(0.5); // jumps to 50%
tl.time(1.5); // jumps to 1.5s
// Speed
tl.timeScale(2); // 2x faster
tl.timeScale(0.5); // 2x slower
// State
tl.isActive(); // currently playing?
tl.totalDuration(); // total duration including repeats
tl.paused(); // paused?
// Modification
tl.clear(); // clears the timeline (keeps the instance)
tl.invalidate(); // resets the starting values
tl.totalProgress(0); // resets to the start
```
## Common patterns
### Responsive timeline with matchMedia
```js
// gsap.matchMedia() (GSAP 3.11+). ScrollTrigger.matchMedia() is deprecated.
const mm = gsap.matchMedia();
mm.add("(min-width: 768px)", () => {
// desktop animations
gsap.timeline({ scrollTrigger: { trigger: ".section" } })
.to(".box", { x: 500 });
});
mm.add("(max-width: 767px)", () => {
// mobile animations (simpler)
gsap.to(".box", { y: 100, scrollTrigger: ".section" });
});
// Automatic revert when the media query no longer matches
```
### Timeline with ScrollTrigger
```js
const tl = gsap.timeline({
scrollTrigger: {
trigger: ".section",
start: "top center",
end: "bottom center",
scrub: 1,
// DO NOT put ScrollTrigger on the timeline's children
},
});
tl.to(".a", { x: 200 })
.to(".b", { rotation: 360 }, "<")
.to(".c", { scale: 2 }, "+=0.3");
```
### Clean kill in React
```jsx
import { useGSAP } from "@gsap/react";
function Component() {
const container = useRef();
useGSAP(() => {
const tl = gsap.timeline();
tl.to(".box", { x: 200 });
// automatic cleanup by useGSAP
}, { scope: container });
return <div ref={container}>...</div>;
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |