@istmx/skills 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -20
- package/bin/cli.js +50 -24
- package/istm-animate/SKILL.md +31 -26
- package/istm-animate/core/motion-principles/SKILL.md +284 -0
- package/istm-animate/core/motion-principles/references/designers.md +127 -0
- package/istm-animate/core/motion-principles/references/easing-guide.md +231 -0
- package/istm-animate/core/motion-principles/references/enter-exit-recipes.md +466 -0
- package/istm-animate/frameworks/canvas-generative/SKILL.md +325 -0
- package/istm-animate/frameworks/canvas-generative/references/algorithms.md +925 -0
- package/istm-animate/frameworks/css-native/SKILL.md +319 -0
- package/istm-animate/frameworks/css-native/references/modern-css.md +465 -0
- package/istm-animate/frameworks/framer-motion/SKILL.md +187 -0
- package/istm-animate/frameworks/framer-motion/references/api.md +312 -0
- package/istm-animate/frameworks/gsap/SKILL.md +188 -0
- package/istm-animate/frameworks/gsap/references/core.md +218 -0
- package/istm-animate/frameworks/gsap/references/plugins.md +371 -0
- package/istm-animate/frameworks/gsap/references/scrolltrigger.md +325 -0
- package/istm-animate/frameworks/gsap/references/timeline.md +218 -0
- package/istm-animate/frameworks/threejs-r3f/SKILL.md +243 -0
- package/istm-animate/frameworks/threejs-r3f/references/scene-setup.md +392 -0
- package/istm-animate/frameworks/threejs-r3f/references/shaders.md +446 -0
- package/istm-animate/mobile/android/compose-graphics/SKILL.md +503 -0
- package/istm-animate/mobile/android/compose-graphics/references/agsl-recipes.md +356 -0
- package/istm-animate/mobile/android/compose-graphics/references/canvas-generative.md +282 -0
- package/istm-animate/mobile/android/compose-graphics/references/m3-expressive-deep.md +303 -0
- package/istm-animate/mobile/android/compose-motion/SKILL.md +359 -0
- package/istm-animate/mobile/android/compose-motion/references/gestures-compose.md +273 -0
- package/istm-animate/mobile/android/compose-motion/references/recomposition-and-anim.md +196 -0
- package/istm-animate/mobile/android/compose-motion/references/shared-transitions.md +281 -0
- package/istm-animate/mobile/android/compose-multiplatform/SKILL.md +311 -0
- package/istm-animate/mobile/android/compose-multiplatform/references/cmp-interop.md +288 -0
- package/istm-animate/mobile/android/compose-multiplatform/references/cmp-platform-quirks.md +156 -0
- package/istm-animate/mobile/apple/swiftui-graphics/SKILL.md +408 -0
- package/istm-animate/mobile/apple/swiftui-graphics/references/canvas-swiftui.md +239 -0
- package/istm-animate/mobile/apple/swiftui-graphics/references/liquid-glass-deep.md +252 -0
- package/istm-animate/mobile/apple/swiftui-graphics/references/metal-recipes.md +382 -0
- package/istm-animate/mobile/apple/swiftui-motion/SKILL.md +379 -0
- package/istm-animate/mobile/apple/swiftui-motion/references/gestures-swiftui.md +336 -0
- package/istm-animate/mobile/apple/swiftui-motion/references/phase-keyframe-deep.md +231 -0
- package/istm-animate/mobile/apple/swiftui-motion/references/springs-cheatsheet.md +129 -0
- package/istm-animate/references/animate.md +199 -0
- package/istm-animate/references/audit.md +115 -0
- package/istm-animate/references/design-engineering.md +674 -0
- package/istm-animate/references/improve.md +101 -0
- package/istm-animate/references/opportunities.md +132 -0
- package/istm-animate/references/plan-template.md +73 -0
- package/istm-animate/references/recipes.md +324 -0
- package/istm-animate/references/review.md +112 -0
- package/istm-animate/references/standards.md +187 -0
- package/istm-animate/references/vocabulary.md +173 -0
- package/istm-awwward-designer/SKILL.md +29 -17
- package/istm-design/SKILL.md +31 -59
- package/istm-design/core/design-audit/SKILL.md +248 -0
- package/istm-design/core/desktop-principles/SKILL.md +363 -0
- package/istm-design/core/desktop-principles/references/keyboard-patterns.md +137 -0
- package/istm-design/core/desktop-principles/references/multi-window.md +105 -0
- package/istm-design/core/mobile-principles/SKILL.md +289 -0
- package/istm-design/core/mobile-principles/references/accessibility-mobile.md +175 -0
- package/istm-design/core/mobile-principles/references/gestures-deep.md +220 -0
- package/istm-design/core/ui-ux-pro-max/SKILL.md +392 -0
- package/istm-design/core/ui-ux-pro-max/UPSTREAM.md +23 -0
- package/istm-design/core/ui-ux-pro-max/data/app-interface.csv +31 -0
- package/istm-design/core/ui-ux-pro-max/data/charts.csv +26 -0
- package/istm-design/core/ui-ux-pro-max/data/colors.csv +193 -0
- package/istm-design/core/ui-ux-pro-max/data/google-fonts.csv +1924 -0
- package/istm-design/core/ui-ux-pro-max/data/icons.csv +106 -0
- package/istm-design/core/ui-ux-pro-max/data/landing.csv +35 -0
- package/istm-design/core/ui-ux-pro-max/data/motion.csv +17 -0
- package/istm-design/core/ui-ux-pro-max/data/products.csv +193 -0
- package/istm-design/core/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/angular.csv +51 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/avalonia.csv +57 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/javafx.csv +76 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/laravel.csv +51 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/nuxt-ui.csv +71 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/threejs.csv +54 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/uno.csv +60 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/uwp.csv +56 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/winui.csv +60 -0
- package/istm-design/core/ui-ux-pro-max/data/stacks/wpf.csv +57 -0
- package/istm-design/core/ui-ux-pro-max/data/styles.csv +85 -0
- package/istm-design/core/ui-ux-pro-max/data/typography.csv +75 -0
- package/istm-design/core/ui-ux-pro-max/data/ui-reasoning.csv +162 -0
- package/istm-design/core/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/istm-design/core/ui-ux-pro-max/references/pro-rules.md +109 -0
- package/istm-design/core/ui-ux-pro-max/references/quick-reference.md +240 -0
- package/istm-design/core/ui-ux-pro-max/scripts/core.py +464 -0
- package/istm-design/core/ui-ux-pro-max/scripts/design_system.py +1371 -0
- package/istm-design/core/ui-ux-pro-max/scripts/search.py +162 -0
- package/istm-design/core/ui-ux-pro-max/scripts/tests/test_core.py +134 -0
- package/istm-design/core/ui-ux-pro-max/scripts/validate_data.py +114 -0
- package/istm-design/references/apple-design.md +282 -0
- package/istm-design/references/generation-guide.md +209 -0
- package/istm-design/references/pick-ui-library.md +77 -0
- package/istm-design/references/picker.md +197 -0
- package/istm-design/references/prototype.md +90 -0
- package/istm-design/references/schema.md +366 -0
- package/package.json +1 -1
- package/RELEASE_v1.2.0.md +0 -40
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# ScrollTrigger
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import gsap from "gsap";
|
|
7
|
+
import { ScrollTrigger } from "gsap/ScrollTrigger";
|
|
8
|
+
gsap.registerPlugin(ScrollTrigger);
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic syntax
|
|
12
|
+
|
|
13
|
+
### On a tween
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
gsap.to(".box", {
|
|
17
|
+
x: 200,
|
|
18
|
+
scrollTrigger: {
|
|
19
|
+
trigger: ".box", // trigger element
|
|
20
|
+
start: "top center", // when the TOP of the trigger reaches the CENTER of the viewport
|
|
21
|
+
end: "bottom center",
|
|
22
|
+
toggleActions: "play none none none",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### On a timeline
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
const tl = gsap.timeline({
|
|
31
|
+
scrollTrigger: {
|
|
32
|
+
trigger: ".section",
|
|
33
|
+
start: "top top",
|
|
34
|
+
end: "+=1000",
|
|
35
|
+
pin: true,
|
|
36
|
+
scrub: 1,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
tl.to(".a", { x: 200 }).to(".b", { y: -100 }, "<");
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Standalone (without tween)
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
ScrollTrigger.create({
|
|
46
|
+
trigger: ".section",
|
|
47
|
+
start: "top center",
|
|
48
|
+
end: "bottom center",
|
|
49
|
+
onEnter: () => console.log("enter"),
|
|
50
|
+
onLeave: () => console.log("leave"),
|
|
51
|
+
toggleClass: "active",
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Properties
|
|
56
|
+
|
|
57
|
+
### trigger
|
|
58
|
+
|
|
59
|
+
Element or selector that defines the trigger zone.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
trigger: ".my-section" // CSS selector
|
|
63
|
+
trigger: elementRef // DOM element
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### start / end
|
|
67
|
+
|
|
68
|
+
Format : `"triggerPoint viewportPoint"`.
|
|
69
|
+
|
|
70
|
+
Possible values for each point: `top`, `center`, `bottom`, percentage (`80%`), pixels (`200px`), or function.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
start: "top center" // top of trigger = center of viewport
|
|
74
|
+
start: "top 80%" // top of trigger = 80% of viewport (from top)
|
|
75
|
+
start: "top top+=100" // top of trigger = top of viewport + 100px
|
|
76
|
+
end: "bottom top" // bottom of trigger = top of viewport
|
|
77
|
+
end: "+=500" // 500px after start
|
|
78
|
+
end: () => "+=" + el.offsetHeight // dynamic
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### scrub
|
|
82
|
+
|
|
83
|
+
Links animation progress to scroll.
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
scrub: true // instant (follows scroll exactly)
|
|
87
|
+
scrub: 0.5 // smooth with 0.5s catch-up
|
|
88
|
+
scrub: 1 // smooth with 1s catch-up (recommended)
|
|
89
|
+
scrub: 3 // very smooth, fluid effect
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### pin
|
|
93
|
+
|
|
94
|
+
Pins the element for the duration of the ScrollTrigger.
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
pin: true // pins the trigger
|
|
98
|
+
pin: ".other-element" // pins another element
|
|
99
|
+
pinSpacing: true // default: adds padding to compensate
|
|
100
|
+
pinSpacing: false // no padding (for overlay effects)
|
|
101
|
+
pinReparent: true // reparents the pin (fixes z-index issues, use with caution)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### snap
|
|
105
|
+
|
|
106
|
+
Snaps progress to specific points after scrolling.
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
snap: 0.25 // snaps every 25%
|
|
110
|
+
snap: [0, 0.25, 0.5, 1] // snaps to specific points
|
|
111
|
+
snap: "labels" // snaps to timeline labels
|
|
112
|
+
|
|
113
|
+
// Advanced config
|
|
114
|
+
snap: {
|
|
115
|
+
snapTo: "labels",
|
|
116
|
+
duration: { min: 0.2, max: 0.8 },
|
|
117
|
+
delay: 0.1,
|
|
118
|
+
ease: "power1.inOut",
|
|
119
|
+
directional: true, // snap in the scroll direction
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### toggleActions
|
|
124
|
+
|
|
125
|
+
Defines behavior at 4 moments: `onEnter`, `onLeave`, `onEnterBack`, `onLeaveBack`.
|
|
126
|
+
|
|
127
|
+
Possible actions: `play`, `pause`, `resume`, `reset`, `restart`, `complete`, `reverse`, `none`.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
toggleActions: "play none none none" // default
|
|
131
|
+
toggleActions: "play pause resume reverse" // classic
|
|
132
|
+
toggleActions: "restart none none reset" // reset on each entry
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### toggleClass
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
toggleClass: "active" // toggle on the trigger
|
|
139
|
+
toggleClass: { targets: ".box", className: "active" } // toggle on other elements
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### markers
|
|
143
|
+
|
|
144
|
+
Visual debug. **Remove in production.**
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
markers: true
|
|
148
|
+
markers: { startColor: "green", endColor: "red", fontSize: "12px" }
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Callbacks
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
ScrollTrigger.create({
|
|
155
|
+
trigger: ".section",
|
|
156
|
+
start: "top center",
|
|
157
|
+
end: "bottom center",
|
|
158
|
+
onEnter: (self) => {}, // scroll down, enters the zone
|
|
159
|
+
onLeave: (self) => {}, // scroll down, exits the zone
|
|
160
|
+
onEnterBack: (self) => {}, // scroll up, re-enters the zone
|
|
161
|
+
onLeaveBack: (self) => {}, // scroll up, exits from the top
|
|
162
|
+
onUpdate: (self) => { // every frame during scrub
|
|
163
|
+
self.progress; // 0-1
|
|
164
|
+
self.direction; // 1 (down) or -1 (up)
|
|
165
|
+
self.isActive; // in the zone?
|
|
166
|
+
self.getVelocity(); // scroll velocity
|
|
167
|
+
},
|
|
168
|
+
onToggle: (self) => {}, // when isActive changes
|
|
169
|
+
onRefresh: (self) => {}, // when positions are recalculated
|
|
170
|
+
onScrubComplete: () => {}, // when scrub finishes catching up
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## containerAnimation
|
|
175
|
+
|
|
176
|
+
Allows creating ScrollTriggers for elements inside a horizontal scroll.
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
// 1. Create the horizontal scroll
|
|
180
|
+
const panels = gsap.utils.toArray(".panel");
|
|
181
|
+
const scrollTween = gsap.to(panels, {
|
|
182
|
+
xPercent: -100 * (panels.length - 1),
|
|
183
|
+
ease: "none", // REQUIRED: ease none on the parent tween
|
|
184
|
+
scrollTrigger: {
|
|
185
|
+
trigger: ".panels-container",
|
|
186
|
+
pin: true,
|
|
187
|
+
scrub: 1,
|
|
188
|
+
end: () => "+=" + document.querySelector(".panels-container").scrollWidth,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// 2. Animate individual elements within the horizontal scroll
|
|
193
|
+
panels.forEach((panel) => {
|
|
194
|
+
gsap.from(panel.querySelector(".content"), {
|
|
195
|
+
opacity: 0,
|
|
196
|
+
y: 50,
|
|
197
|
+
scrollTrigger: {
|
|
198
|
+
trigger: panel,
|
|
199
|
+
containerAnimation: scrollTween, // LINKED to horizontal scroll
|
|
200
|
+
start: "left center", // horizontal axes!
|
|
201
|
+
end: "center center",
|
|
202
|
+
scrub: true,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**containerAnimation pitfalls**:
|
|
209
|
+
- The parent tween MUST have `ease: "none"`
|
|
210
|
+
- start/end use horizontal axes (`left`, `right`, `center`)
|
|
211
|
+
- Do NOT put `pin` on child ScrollTriggers
|
|
212
|
+
- Do NOT use `snap` on children
|
|
213
|
+
|
|
214
|
+
## ScrollTrigger.batch()
|
|
215
|
+
|
|
216
|
+
Animates elements in batches when they enter the viewport. Ideal for grids.
|
|
217
|
+
|
|
218
|
+
```js
|
|
219
|
+
ScrollTrigger.batch(".card", {
|
|
220
|
+
onEnter: (elements, triggers) => {
|
|
221
|
+
gsap.to(elements, {
|
|
222
|
+
opacity: 1,
|
|
223
|
+
y: 0,
|
|
224
|
+
stagger: 0.1,
|
|
225
|
+
overwrite: true,
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
onLeave: (elements) => {
|
|
229
|
+
gsap.set(elements, { opacity: 0, y: 30 });
|
|
230
|
+
},
|
|
231
|
+
onEnterBack: (elements) => {
|
|
232
|
+
gsap.to(elements, { opacity: 1, y: 0, stagger: 0.1 });
|
|
233
|
+
},
|
|
234
|
+
start: "top 85%",
|
|
235
|
+
// interval: 0.1, // batching time (default: 0.1s)
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// Initial setup
|
|
239
|
+
gsap.set(".card", { opacity: 0, y: 30 });
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## matchMedia
|
|
243
|
+
|
|
244
|
+
Responsive animations with automatic cleanup.
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
// gsap.matchMedia() (GSAP 3.11+). ScrollTrigger.matchMedia() is deprecated.
|
|
248
|
+
const mm = gsap.matchMedia();
|
|
249
|
+
|
|
250
|
+
// Desktop
|
|
251
|
+
mm.add("(min-width: 960px)", () => {
|
|
252
|
+
gsap.to(".box", {
|
|
253
|
+
x: 500,
|
|
254
|
+
scrollTrigger: { trigger: ".section", scrub: true },
|
|
255
|
+
});
|
|
256
|
+
// Everything created inside is auto-reverted when the query stops matching
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// Mobile
|
|
260
|
+
mm.add("(max-width: 959px)", () => {
|
|
261
|
+
gsap.to(".box", {
|
|
262
|
+
y: 200,
|
|
263
|
+
scrollTrigger: { trigger: ".section", scrub: true },
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// All sizes
|
|
268
|
+
mm.add("all", () => {
|
|
269
|
+
gsap.to(".always", { opacity: 1 });
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Refresh
|
|
274
|
+
|
|
275
|
+
ScrollTrigger recalculates positions on resize. Sometimes you need to force it manually:
|
|
276
|
+
|
|
277
|
+
```js
|
|
278
|
+
// After loading images, dynamic content changes, etc.
|
|
279
|
+
ScrollTrigger.refresh();
|
|
280
|
+
|
|
281
|
+
// Wait for fonts/images to load
|
|
282
|
+
ScrollTrigger.refresh(true); // safe mode: waits for the next tick
|
|
283
|
+
|
|
284
|
+
// Recalculate a single ScrollTrigger
|
|
285
|
+
myTrigger.refresh();
|
|
286
|
+
|
|
287
|
+
// Sort order: controls refresh order
|
|
288
|
+
ScrollTrigger.sort(); // sorts by start position (recommended after dynamic additions)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Useful static methods
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
ScrollTrigger.getAll() // all active ScrollTriggers
|
|
295
|
+
ScrollTrigger.getById("myId") // by id
|
|
296
|
+
ScrollTrigger.killAll() // destroys all
|
|
297
|
+
ScrollTrigger.saveStyles(".box") // saves styles before matchMedia
|
|
298
|
+
ScrollTrigger.scrollerProxy(el, {}) // custom scroller (Locomotive, Lenis)
|
|
299
|
+
ScrollTrigger.normalizeScroll(true) // normalizes touch scroll (anti-overscroll)
|
|
300
|
+
ScrollTrigger.config({ limitCallbacks: true }) // optimize perf
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Smooth scroll integration (Lenis)
|
|
304
|
+
|
|
305
|
+
```js
|
|
306
|
+
import Lenis from "lenis";
|
|
307
|
+
|
|
308
|
+
const lenis = new Lenis();
|
|
309
|
+
lenis.on("scroll", ScrollTrigger.update);
|
|
310
|
+
gsap.ticker.add((time) => lenis.raf(time * 1000));
|
|
311
|
+
gsap.ticker.lagSmoothing(0);
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Cleanup (React)
|
|
315
|
+
|
|
316
|
+
```jsx
|
|
317
|
+
useGSAP(() => {
|
|
318
|
+
ScrollTrigger.create({
|
|
319
|
+
trigger: sectionRef.current,
|
|
320
|
+
start: "top center",
|
|
321
|
+
onEnter: () => { /* ... */ },
|
|
322
|
+
});
|
|
323
|
+
// useGSAP automatically kills all ScrollTriggers created within the scope
|
|
324
|
+
}, { scope: containerRef });
|
|
325
|
+
```
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# GSAP Timeline
|
|
2
|
+
|
|
3
|
+
## Creation
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
const tl = gsap.timeline({
|
|
7
|
+
defaults: { duration: 0.8, ease: "power2.out" }, // applies to all children
|
|
8
|
+
paused: false,
|
|
9
|
+
repeat: -1, // -1 = infinite
|
|
10
|
+
yoyo: true,
|
|
11
|
+
repeatDelay: 0.5,
|
|
12
|
+
onComplete: () => console.log("done"),
|
|
13
|
+
});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Position Parameter
|
|
17
|
+
|
|
18
|
+
The position parameter controls WHERE a tween is inserted in the timeline. It's the 3rd argument of `.to()`, `.from()`, `.fromTo()`, `.add()`.
|
|
19
|
+
|
|
20
|
+
### Absolute values
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
tl.to(".a", { x: 100 }, 0); // at exactly 0s (start of the timeline)
|
|
24
|
+
tl.to(".b", { x: 100 }, 1); // at exactly 1s
|
|
25
|
+
tl.to(".c", { x: 100 }, 2.5); // at exactly 2.5s
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Relative to the end of the timeline
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
tl.to(".a", { x: 100 }); // appends to the end
|
|
32
|
+
tl.to(".b", { x: 100 }, "+=0.5"); // 0.5s AFTER the end
|
|
33
|
+
tl.to(".c", { x: 100 }, "-=0.3"); // 0.3s BEFORE the end (overlap)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Relative to the previous tween
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
tl.to(".a", { x: 100 });
|
|
40
|
+
tl.to(".b", { x: 100 }, "<"); // same start as the previous
|
|
41
|
+
tl.to(".c", { x: 100 }, "<0.2"); // 0.2s after the START of the previous
|
|
42
|
+
tl.to(".d", { x: 100 }, ">"); // at the END of the previous
|
|
43
|
+
tl.to(".e", { x: 100 }, ">-0.1"); // 0.1s BEFORE the end of the previous
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### With labels
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
tl.addLabel("intro", 1);
|
|
50
|
+
tl.to(".a", { x: 100 }, "intro"); // at the label
|
|
51
|
+
tl.to(".b", { x: 100 }, "intro+=0.3"); // 0.3s after the label
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Position cheatsheet
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
tl ─────────────────────────────────────>
|
|
58
|
+
| A | | B |
|
|
59
|
+
| C | | D |
|
|
60
|
+
| E |
|
|
61
|
+
|
|
62
|
+
A: tl.to(a, {}, 0) // absolute
|
|
63
|
+
B: tl.to(b, {}) // sequential (end of A)
|
|
64
|
+
C: tl.to(c, {}, "<") // start of B
|
|
65
|
+
D: tl.to(d, {}, "+=0.5") // 0.5s after end of C
|
|
66
|
+
E: tl.to(e, {}, ">-0.2") // 0.2s before end of D
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Labels
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
tl.addLabel("reveal", "+=0.5"); // adds a label at the current position + 0.5s
|
|
73
|
+
tl.to(".box", { x: 200 }, "reveal"); // uses the label as position
|
|
74
|
+
|
|
75
|
+
tl.play("reveal"); // plays from the label
|
|
76
|
+
tl.seek("reveal"); // jumps to the label without playing
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## .add() method
|
|
80
|
+
|
|
81
|
+
Adds tweens, callbacks, or labels.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
tl.add(gsap.to(".a", { x: 100 }), 1); // tween at 1s
|
|
85
|
+
tl.add(() => console.log("checkpoint"), "+=0.5"); // callback
|
|
86
|
+
tl.add("myLabel"); // label shorthand
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Nesting (nested timelines)
|
|
90
|
+
|
|
91
|
+
Timelines can contain other timelines. Each sub-timeline acts as a single "block" in the parent.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
function heroAnimation() {
|
|
95
|
+
const tl = gsap.timeline();
|
|
96
|
+
tl.from(".hero-title", { y: 50, opacity: 0 })
|
|
97
|
+
.from(".hero-subtitle", { y: 30, opacity: 0 }, "<0.2")
|
|
98
|
+
.from(".hero-cta", { scale: 0.8, opacity: 0 }, "<0.1");
|
|
99
|
+
return tl;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function cardsAnimation() {
|
|
103
|
+
const tl = gsap.timeline();
|
|
104
|
+
tl.from(".card", { y: 40, opacity: 0, stagger: 0.15 });
|
|
105
|
+
return tl;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Master timeline
|
|
109
|
+
const master = gsap.timeline();
|
|
110
|
+
master
|
|
111
|
+
.add(heroAnimation())
|
|
112
|
+
.add(cardsAnimation(), "-=0.3"); // 0.3s overlap
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Advantage**: each section is encapsulated, testable, and repositionable.
|
|
116
|
+
|
|
117
|
+
## defaults on Timeline
|
|
118
|
+
|
|
119
|
+
Defaults propagate to direct children but NOT to nested timelines.
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
const tl = gsap.timeline({
|
|
123
|
+
defaults: { duration: 1, ease: "power3.out" },
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
tl.to(".a", { x: 100 }); // duration: 1, ease: power3.out
|
|
127
|
+
tl.to(".b", { x: 100, duration: 2 }); // duration: 2 (override), ease: power3.out
|
|
128
|
+
|
|
129
|
+
// Child timeline: its own defaults apply
|
|
130
|
+
const child = gsap.timeline({ defaults: { duration: 0.5 } });
|
|
131
|
+
tl.add(child); // the parent's defaults do NOT apply to child's tweens
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Controlling the Timeline
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
tl.play();
|
|
138
|
+
tl.pause();
|
|
139
|
+
tl.resume();
|
|
140
|
+
tl.reverse();
|
|
141
|
+
tl.restart();
|
|
142
|
+
tl.kill();
|
|
143
|
+
|
|
144
|
+
// Navigation
|
|
145
|
+
tl.seek(2); // jumps to 2s
|
|
146
|
+
tl.seek("myLabel"); // jumps to the label
|
|
147
|
+
tl.progress(0.5); // jumps to 50%
|
|
148
|
+
tl.time(1.5); // jumps to 1.5s
|
|
149
|
+
|
|
150
|
+
// Speed
|
|
151
|
+
tl.timeScale(2); // 2x faster
|
|
152
|
+
tl.timeScale(0.5); // 2x slower
|
|
153
|
+
|
|
154
|
+
// State
|
|
155
|
+
tl.isActive(); // currently playing?
|
|
156
|
+
tl.totalDuration(); // total duration including repeats
|
|
157
|
+
tl.paused(); // paused?
|
|
158
|
+
|
|
159
|
+
// Modification
|
|
160
|
+
tl.clear(); // clears the timeline (keeps the instance)
|
|
161
|
+
tl.invalidate(); // resets the starting values
|
|
162
|
+
tl.totalProgress(0); // resets to the start
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Common patterns
|
|
166
|
+
|
|
167
|
+
### Responsive timeline with matchMedia
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
// gsap.matchMedia() (GSAP 3.11+). ScrollTrigger.matchMedia() is deprecated.
|
|
171
|
+
const mm = gsap.matchMedia();
|
|
172
|
+
mm.add("(min-width: 768px)", () => {
|
|
173
|
+
// desktop animations
|
|
174
|
+
gsap.timeline({ scrollTrigger: { trigger: ".section" } })
|
|
175
|
+
.to(".box", { x: 500 });
|
|
176
|
+
});
|
|
177
|
+
mm.add("(max-width: 767px)", () => {
|
|
178
|
+
// mobile animations (simpler)
|
|
179
|
+
gsap.to(".box", { y: 100, scrollTrigger: ".section" });
|
|
180
|
+
});
|
|
181
|
+
// Automatic revert when the media query no longer matches
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Timeline with ScrollTrigger
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
const tl = gsap.timeline({
|
|
188
|
+
scrollTrigger: {
|
|
189
|
+
trigger: ".section",
|
|
190
|
+
start: "top center",
|
|
191
|
+
end: "bottom center",
|
|
192
|
+
scrub: 1,
|
|
193
|
+
// DO NOT put ScrollTrigger on the timeline's children
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
tl.to(".a", { x: 200 })
|
|
198
|
+
.to(".b", { rotation: 360 }, "<")
|
|
199
|
+
.to(".c", { scale: 2 }, "+=0.3");
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Clean kill in React
|
|
203
|
+
|
|
204
|
+
```jsx
|
|
205
|
+
import { useGSAP } from "@gsap/react";
|
|
206
|
+
|
|
207
|
+
function Component() {
|
|
208
|
+
const container = useRef();
|
|
209
|
+
|
|
210
|
+
useGSAP(() => {
|
|
211
|
+
const tl = gsap.timeline();
|
|
212
|
+
tl.to(".box", { x: 200 });
|
|
213
|
+
// automatic cleanup by useGSAP
|
|
214
|
+
}, { scope: container });
|
|
215
|
+
|
|
216
|
+
return <div ref={container}>...</div>;
|
|
217
|
+
}
|
|
218
|
+
```
|