Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

feat: add 5 READMEs and update category/root indexes

matind53ddccff2cf
diff --git a/animations/01-scroll-based/README.md b/animations/01-scroll-based/README.md
index 8f12551b..94cb7ffe 100644
--- a/animations/01-scroll-based/README.md
+++ b/animations/01-scroll-based/README.md
@@ -14,3 +14,13 @@ Techniques driven by scroll position.
into a compact fixed header; every visual property driven by a single 0→1 progress value.
- [Fly-in Fly-out Contact List](fly-in-fly-out-contact-list/) — rows translate and fade
as they enter and exit the scroll viewport; effect scrubbed continuously to scroll position.
+- [Stacking Cards](stacking-cards/) — cards stack visually as they overlap; position: sticky
+ does the work, scroll drives optional depth cues via scale and brightness.
+- [ScrollTrigger Animation](scroll-trigger/) — demonstrates the onEnter/onLeave/onEnterBack/
+ onLeaveBack lifecycle using IntersectionObserver and vanilla scroll events.
+- [Scrub Animation](scrub-animation/) — a camera lens disassembles in five stages as you scroll;
+ every transform is welded to scroll position with no autoplay.
+- [Pin Animation](pin-animation/) — a phone mockup and feature copy pin to the viewport via
+ CSS sticky while four features swap in sequence during the scroll.
+- [Snap Scrolling](snap-scrolling/) — CSS scroll-snap-type creates a paginated, magnetic feel;
+ switch between mandatory, proximity, and none to feel the difference.
diff --git a/animations/01-scroll-based/pin-animation/README.md b/animations/01-scroll-based/pin-animation/README.md
new file mode 100644
index 00000000..f53e2c57
--- /dev/null
+++ b/animations/01-scroll-based/pin-animation/README.md
@@ -0,0 +1,68 @@
+# Pin Animation
+
+[Live demo](index.html)
+
+## What it is
+
+An element that freezes in place while the page continues to scroll beneath it. The pinned element appears to hover at a fixed position in the viewport while the user scrolls through a defined section. In this demo, a phone mockup and its paired feature copy pin to the center of the viewport as the user scrolls through a section three times the viewport height. Four features swap in sequence as scroll progresses through the pinned zone, then the pin releases and scroll continues normally. CSS `position: sticky` handles the entire pin — no JavaScript pinning.
+
+## When to use it
+
+- Apple-style product feature walkthroughs where one UI element stays visible while explanatory copy advances
+- Step-by-step onboarding where a persistent element stays in view through multiple scroll steps
+- Any layout where a visual anchor must be stable while surrounding context changes
+- Tutorial sequences where maintaining spatial continuity aids comprehension
+
+## How it works
+
+The pin requires only three things: a tall parent section, a sticky child, and matching heights:
+
+```css
+.pin-section {
+ height: 1860px; /* 3× the viewport height */
+}
+.pin-inner {
+ position: sticky;
+ top: 0;
+ height: 620px; /* matches the viewport/stage height */
+}
+```
+
+JavaScript computes which feature to show based on position within the section:
+
+```js
+const pinStart = pinSection.offsetTop;
+const pinHeight = 1860;
+const viewH = 620;
+const p = clamp((scrollTop - pinStart) / (pinHeight - viewH), 0, 1);
+const featureIndex = Math.min(3, Math.floor(p * 4));
+```
+
+The lifecycle is derived from the same values:
+
+```js
+const lifecycle =
+ scrollTop < pinStart ? 'before pin'
+ : scrollTop < pinStart + pinHeight - viewH ? 'pinned · in section'
+ : 'after release';
+```
+
+## Key parameters
+
+| Parameter | Default | Effect |
+|-----------|---------|--------|
+| Pin section height | `3× viewport height` | Total scroll distance through the pin |
+| Feature count | 4 | Features are evenly spaced across the pin section |
+| `sticky top` | `0` | The viewport offset where pinning engages |
+
+## Production notes
+
+- **The "extra height" is the scroll budget.** A pinned element at `top: 0` stays visible for exactly `(parent height − viewport height)` pixels of scroll. Set the parent height to `viewport_height + scroll_budget`.
+- **GSAP `pin: true`** in ScrollTrigger replicates this behavior and adds smoother feature transitions and timeline scrubbing. Locomotive Scroll and Lenis both support pinned sections natively with their inertia-based scroll.
+- **Performance.** The pinned content is not animating — it is just sticky. Feature swaps are text/class changes. No GPU compositing is required beyond what `position: sticky` establishes.
+- **Accessibility.** Pin sections that scroll silently while content changes can confuse screen reader users. Ensure feature changes are announced via `aria-live` or that the logical reading order is preserved in the DOM.
+
+## See also
+
+- [Scrub Animation](../scrub-animation/) — uses the same scroll-progress model but continuously transforms a single element rather than swapping discrete features.
+- [ScrollTrigger Animation](../scroll-trigger/) — the conceptual framework that defines pin, scrub, and snap as scroll trigger behaviors.
diff --git a/animations/01-scroll-based/scroll-trigger/README.md b/animations/01-scroll-based/scroll-trigger/README.md
new file mode 100644
index 00000000..7efa912a
--- /dev/null
+++ b/animations/01-scroll-based/scroll-trigger/README.md
@@ -0,0 +1,58 @@
+# ScrollTrigger Animation
+
+[Live demo](index.html)
+
+## What it is
+
+ScrollTrigger is not an animation type — it is a mechanism that fires animations at precise scroll positions. It defines scroll zones and exposes a lifecycle: `onEnter` (zone enters viewport), `onLeave` (zone exits at top), `onEnterBack` (zone re-enters from top on scroll-up), `onLeaveBack` (zone exits at bottom on scroll-up). This demo implements the concept in vanilla JS using `IntersectionObserver`, showing four core behaviors: fade on enter, scrub with scroll, pin and scrub, and snap to points. In production, GSAP's ScrollTrigger plugin handles all of this.
+
+## When to use it
+
+- Any element that should animate exactly once as it enters the viewport
+- Product reveals, feature lists, and section transitions requiring scroll-coordinated timing
+- Marketing pages that must remain accessible without JavaScript by having logical resting states
+- Any scenario requiring precise callbacks at scroll boundaries, not just "is it visible?"
+
+## How it works
+
+Each scroll zone uses an `IntersectionObserver` for lifecycle callbacks:
+
+```js
+const io = new IntersectionObserver(entries => {
+ entries.forEach(e => {
+ if (!wasActive && e.isIntersecting) fire(zone, 'onEnter');
+ if (wasActive && !e.isIntersecting)
+ fire(zone, scrollDir > 0 ? 'onLeave' : 'onLeaveBack');
+ });
+}, { root: stage, threshold: 0 });
+```
+
+For the scrub zone, scroll position is normalized to `0–1` and applied directly to transforms:
+
+```js
+const p = clamp((scrollTop - zone.offsetTop) / zone.offsetHeight, 0, 1);
+swatch.style.transform = `rotate(${p * 180}deg) scale(${lerp(1, 1.3, p)})`;
+swatch.style.filter = `hue-rotate(${p * 120}deg)`;
+```
+
+## Key parameters
+
+| Parameter | Default | Effect |
+|-----------|---------|--------|
+| Observer `rootMargin` | `0px` | Expand to pre-trigger animations before zone is fully visible |
+| Observer `threshold` | `0` | 0 = fire on first pixel; 1 = fire only when fully in view |
+| Scrub zone start | `zone.offsetTop` | Where the scrub progress begins |
+| Snap debounce | 200ms | Delay after scroll-stop before snap fires |
+
+## Production notes
+
+- **GSAP ScrollTrigger** is the production standard. It handles scroll direction, pinning, scrubbing, snapping, and lifecycle callbacks with a clean declarative API. The vanilla JS approach here is educational — it replicates the underlying mechanics without GSAP's optimizations.
+- **`IntersectionObserver` vs. scroll events.** IO is the right tool for lifecycle callbacks (enter/leave). Scroll events with `offsetTop` arithmetic are right for scrubbing. Use both together.
+- **Scrub and `will-change`.** For elements that update on every scroll frame, declare `will-change: transform` before the first frame to avoid promotion jank.
+- **Snap-to-point** requires detecting scroll silence. A debounce timer (100–200ms) after the last scroll event is the reliable pattern; there is no native "scroll ended" event in most browser contexts.
+- **Accessibility.** `onEnter` animations should respect `prefers-reduced-motion`. In reduced-motion mode, jump elements directly to their final state at page load.
+
+## See also
+
+- [Scrub Animation](../scrub-animation/) — a full scrub-driven product disassembly using the same scroll-as-progress model.
+- [Pin Animation](../pin-animation/) — demonstrates the "pin" behavior from the same ScrollTrigger concept.
diff --git a/animations/01-scroll-based/scrub-animation/README.md b/animations/01-scroll-based/scrub-animation/README.md
new file mode 100644
index 00000000..0bab7cb9
--- /dev/null
+++ b/animations/01-scroll-based/scrub-animation/README.md
@@ -0,0 +1,64 @@
+# Scrub Animation
+
+[Live demo](index.html)
+
+## What it is
+
+A multi-stage product disassembly animation where every transform is welded directly to scroll position. There is no autoplay, no duration, no easing that runs independently — scroll IS the seek bar. Scrubbing backward reassembles the product perfectly because animation state is computed entirely from a single `0–1` progress value derived from `scrollTop`. This demo shows a camera lens disassembling in five stages across ~800px of scroll distance.
+
+## When to use it
+
+- Product reveal pages where the user controls the pace of the reveal
+- Technical explainer sequences — processors, architecture, mechanical parts — that benefit from user-controlled inspection
+- Apple-style feature walkthroughs where each scroll increment advances the story
+- Any animation that must be perfectly reversible and inspectable at any intermediate state
+
+## How it works
+
+The entire animation runs from one number:
+
+```js
+const progress = stage.scrollTop / (stage.scrollHeight - stage.clientHeight); // 0→1
+```
+
+Each stage occupies an 18% slice of the progress range. A `clamp` function extracts a local `t` for each stage:
+
+```js
+const t1 = clamp(progress / 0.18, 0, 1); // Stage 1: 0–18%
+const t2 = clamp((progress - 0.18) / 0.18, 0, 1); // Stage 2: 18–36%
+// …and so on
+```
+
+Each SVG element's transform is applied in the rAF callback:
+
+```js
+lensHood.style.transform = `translateY(${lerp(0, -70, t1)}px)`;
+lensGlass.style.transform = `translateY(${lerp(0, -45, t2)}px) scale(${lerp(1, 1.15, t2)})`;
+iris.style.transform = `rotate(${lerp(0, 90, t3)}deg)`;
+lensBody.style.transform = `translateX(${lerp(0, -65, t4)}px)`;
+lensCore.style.transform = `scale(${lerp(1, 2, t5)})`;
+```
+
+Reversing is automatic — `progress` decreases when scrolling up, so all `lerp` calls return earlier values.
+
+## Key parameters
+
+| Parameter | Default | Effect |
+|-----------|---------|--------|
+| Stage count | 5 | Number of distinct disassembly phases |
+| Stage width | 18% | Fraction of total progress range per stage |
+| Scroll travel | ~800px | Total scroll distance for the full animation |
+| `lerp(a, b, t)` | — | Linear interpolation between start and end transform values |
+
+## Production notes
+
+- **No `setInterval`, no animation loops.** The only "loop" is the rAF-throttled scroll listener. Scrub animations have no concept of time, only position.
+- **GSAP ScrollTrigger with `scrub: true`** is the production equivalent. A GSAP timeline is linked to scroll with `scrub: 1` (smoothing lag). The timeline treats `progress` as its playhead. Framer Motion's `useScroll` + `useTransform` achieves the same in React.
+- **SVG transforms.** Set `transform-box: fill-box; transform-origin: center` in CSS so rotation and scale behave relative to each SVG element's own center rather than the SVG viewport origin.
+- **Easing within stages.** This demo uses linear interpolation. In production, apply a per-stage easing function to `t` before passing to `lerp` — this lets parts accelerate into or decelerate out of each stage.
+- **Accessibility.** Continuous scroll-driven motion is a vestibular concern. Under `prefers-reduced-motion: reduce`, skip all transforms and show the fully assembled state statically.
+
+## See also
+
+- [ScrollTrigger Animation](../scroll-trigger/) — the broader scroll trigger concept this pattern uses.
+- [Pin Animation](../pin-animation/) — a complementary pattern where content pins and advances in steps rather than scrubbing continuously.
diff --git a/animations/01-scroll-based/snap-scrolling/README.md b/animations/01-scroll-based/snap-scrolling/README.md
new file mode 100644
index 00000000..775d0e5e
--- /dev/null
+++ b/animations/01-scroll-based/snap-scrolling/README.md
@@ -0,0 +1,68 @@
+# Snap Scrolling
+
+[Live demo](index.html)
+
+## What it is
+
+Snap scrolling makes the viewport magnetize to predefined scroll positions after the user releases a scroll gesture. Instead of stopping at an arbitrary mid-section position, the browser eases to the nearest snap point. The effect creates a deliberate, paginated feel — sections become destinations rather than arbitrary points in a continuous stream. This demo uses the native CSS `scroll-snap-type` and `scroll-snap-align` properties. No JavaScript drives the magnetism; the browser handles it entirely.
+
+## When to use it
+
+- Landing pages where each section is a complete unit of information and partial views are awkward
+- Mobile-first presentations where swipe-based pagination matches native app conventions
+- Slideshows, product galleries, and feature walkthroughs with a defined number of discrete steps
+- Any layout where mid-section scroll positions feel accidental rather than intentional
+
+## How it works
+
+Three CSS properties implement the entire mechanism:
+
+```css
+/* On the scroll container */
+.stage {
+ overflow-y: scroll;
+ scroll-snap-type: y mandatory; /* or 'y proximity' */
+}
+
+/* On each section */
+.section {
+ height: 620px; /* matches the container height */
+ scroll-snap-align: start;
+}
+```
+
+`mandatory` forces a snap on every scroll-end. `proximity` snaps only when the user is close to a snap point. `none` disables snapping. The mode toggle in the demo changes `scroll-snap-type` live.
+
+Pagination dots and jump-to buttons use `scrollTo` with `behavior: 'smooth'`:
+
+```js
+stage.scrollTo({ top: sectionIndex * sectionHeight, behavior: 'smooth' });
+```
+
+Current section is derived from scroll position:
+
+```js
+const sectionIndex = Math.round(stage.scrollTop / sectionHeight);
+```
+
+## Key parameters
+
+| Parameter | Default | Effect |
+|-----------|---------|--------|
+| `scroll-snap-type` | `y mandatory` | `mandatory` = always snaps; `proximity` = snaps when close; `none` = off |
+| `scroll-snap-align` | `start` | Where the snap point lands: `start`, `center`, or `end` |
+| `scroll-behavior` | `smooth` | Affects programmatic `scrollTo` calls, not the snap itself |
+| Section height | `620px` | Must match stage height for full-page snapping |
+
+## Production notes
+
+- **CSS is the entire mechanism.** Snap scrolling requires no JavaScript for the snapping itself. JS is only needed for auxiliary UI — pagination indicators, jump buttons, or syncing external state to the current section.
+- **`mandatory` vs. `proximity`.** Use `mandatory` when every section is viewport-height and partial views are never desirable. Use `proximity` when sections have varying heights or when you want snap behavior only on deliberate gestures. `mandatory` with small scroll steps (keyboard arrows) can feel locked and jarring.
+- **Mobile Safari.** iOS Safari has historically had issues with `scroll-snap-type` inside overflow containers. Test on real devices. Workarounds include using `overflow: auto` instead of `scroll`.
+- **No library needed.** Unlike most other entries in this atlas, snap scrolling requires nothing beyond the browser. The feature is native and well-supported across all modern browsers.
+- **Accessibility.** Snap scrolling can frustrate keyboard users who expect continuous scroll. Ensure the `Tab` key navigates between sections, section headings are focusable, and skip-nav links exist.
+
+## See also
+
+- [Stacking Cards](../stacking-cards/) — another paginated-feel scroll pattern, implemented with sticky stacking rather than snap.
+- [Fly-in Fly-out Contact List](../fly-in-fly-out-contact-list/) — continuous scroll with per-element transitions rather than section-level snapping.
diff --git a/animations/01-scroll-based/stacking-cards/README.md b/animations/01-scroll-based/stacking-cards/README.md
new file mode 100644
index 00000000..4a2816a9
--- /dev/null
+++ b/animations/01-scroll-based/stacking-cards/README.md
@@ -0,0 +1,61 @@
+# Stacking Cards
+
+[Live demo](index.html)
+
+## What it is
+
+A set of cards that stack on top of each other as the user scrolls. Each card is roughly viewport-height tall and uses `position: sticky` to pin itself to the top of the scroll container. As subsequent cards scroll up, they layer over the previous ones, building a literal physical stack. Subtle depth cues — scale reduction, brightness dimming, and a small downward shift — reinforce the sense that buried cards are physically behind the topmost one.
+
+## When to use it
+
+- Portfolio or case-study pages where each project deserves its own full-screen moment
+- Onboarding sequences where each step replaces rather than follows the previous
+- Storytelling layouts where one message must fully resolve before the next appears
+- Any context where scroll should feel like turning pages rather than moving a camera
+
+## How it works
+
+The stacking itself requires only CSS. Each card is `position: sticky; top: 0` inside a tall container. The browser keeps each card at the top of the viewport until the next one scrolls past it. Cards are layered using `z-index` so later cards render on top.
+
+```css
+.card {
+ position: sticky;
+ top: 0;
+ height: 600px;
+ z-index: var(--card-index); /* increases per card */
+}
+```
+
+JavaScript computes the depth of each card — how many cards are stacked on top of it — and applies visual cues proportionally:
+
+```js
+const cardH = 600;
+const topmost = Math.min(Math.floor(scrollTop / cardH), cards.length - 1);
+const depth = Math.max(0, topmost - cardIndex);
+const t = depth / (cards.length - 1); // 0 = surface, 1 = deepest
+
+card.style.transform = `translateY(${depth * 5}px) scale(${lerp(1, SCALE_FLOOR, t)})`;
+card.style.filter = `brightness(${lerp(1, BRIGHT_FLOOR, t)})`;
+```
+
+## Key parameters
+
+| Parameter | Default | Effect |
+|-----------|---------|--------|
+| Scale floor | 0.94 | Minimum scale for buried cards; lower = more pronounced depth |
+| Brightness floor | 0.85 | Minimum brightness for buried cards; lower = darker depth shadow |
+| Card height | 600px | Must match `height` in CSS for correct depth calculation |
+| Translate per depth | 5px | Downward shift per depth level; creates a sinking sensation |
+
+## Production notes
+
+- **CSS does the work; JS adds polish.** The stacking is correct with zero JavaScript — cards appear in the right order purely from `position: sticky` and `z-index`. JavaScript is only needed for the depth cues (scale, brightness). Set both sliders to their max values to see the CSS-only version.
+- **Animating `filter: brightness()` is GPU-composited.** It does not trigger layout or paint. Scale via `transform` is equally safe. Both are compositor-only properties.
+- **Card height must be consistent.** The depth calculation uses a fixed card height. If cards have varying heights, compute `offsetTop` from the DOM rather than multiplying by a constant.
+- **GSAP ScrollTrigger** with `pin: true` on each card and a `scrub` timeline can drive the same scale/brightness cues with more per-card easing control. Framer Motion's `useScroll` + `useTransform` achieves the same in React with viewport-relative progress per element.
+- **Accessibility.** The scale and brightness changes are subtle and unlikely to trigger vestibular discomfort. Under `prefers-reduced-motion: reduce`, disable the depth cues entirely — the stacking still reads clearly from z-order alone.
+
+## See also
+
+- [Cover Card to Fixed Header](../cover-card-to-fixed-header/) — a related full-screen card pattern where scroll collapses rather than stacks.
+- [Parallax Scrolling](../parallax-scrolling/) — another layered-depth scroll technique using speed differentials rather than stacking.
diff --git a/index.html b/index.html
index 278ce358..94ebc56f 100644
--- a/index.html
+++ b/index.html
@@ -43,6 +43,26 @@
<a href="animations/01-scroll-based/fly-in-fly-out-contact-list/">Fly-in Fly-out Contact List</a>
<span class="desc" style="display:block">Contact rows translate and fade through entry, active, and exit zones as you scroll — a continuous bidirectional effect scrubbed to scroll position.</span>
</li>
+ <li>
+ <a href="animations/01-scroll-based/stacking-cards/">Stacking Cards</a>
+ <span class="desc" style="display:block">Cards stack as they overlap — position: sticky handles the layering, scroll drives depth cues via scale and brightness.</span>
+ </li>
+ <li>
+ <a href="animations/01-scroll-based/scroll-trigger/">ScrollTrigger Animation</a>
+ <span class="desc" style="display:block">The onEnter / onLeave lifecycle demonstrated with vanilla JS — four zones showing fade-on-enter, scrub, pin+scrub, and snap.</span>
+ </li>
+ <li>
+ <a href="animations/01-scroll-based/scrub-animation/">Scrub Animation</a>
+ <span class="desc" style="display:block">A camera lens disassembles in five stages as you scroll — every transform welded to scroll position, no autoplay.</span>
+ </li>
+ <li>
+ <a href="animations/01-scroll-based/pin-animation/">Pin Animation</a>
+ <span class="desc" style="display:block">A phone mockup pins to the viewport while four features swap in sequence — CSS position: sticky, no JavaScript pinning.</span>
+ </li>
+ <li>
+ <a href="animations/01-scroll-based/snap-scrolling/">Snap Scrolling</a>
+ <span class="desc" style="display:block">CSS scroll-snap-type creates a paginated, magnetic feel — switch between mandatory, proximity, and none to feel the difference.</span>
+ </li>
</ul>
</body>
</html>