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.

docs: American spelling in the READMEs (center, color, normalize, rasterize, honoring, math), and the Scroll-Triggered Animation snippet names the piece's middle mid, as the demo does

matin9cd7de6bbcd8
diff --git a/animations/01-scroll-based/parallax-scrolling/README.md b/animations/01-scroll-based/parallax-scrolling/README.md
index 0d1061fb..cc4218c0 100644
--- a/animations/01-scroll-based/parallax-scrolling/README.md
+++ b/animations/01-scroll-based/parallax-scrolling/README.md
@@ -20,7 +20,7 @@ the scene feels.
## How it works
Each layer has a speed multiplier `s` between 0 and 1.5, set by the Depth
-setting. On scroll, a single `requestAnimationFrame` callback normalises
+setting. On scroll, a single `requestAnimationFrame` callback normalizes
`scrollTop` to a 0–1 progress value and scales the travel, a quarter of the
box's height, by the layer's speed:
@@ -30,7 +30,7 @@ const offset = progress * MAX_PARALLAX * speed; // MAX_PARALLAX = a
layer.el.style.transform = `translate3d(0, ${offset}px, 0)`;
```
-Normalising first makes the movement the same whatever the length of the
+Normalizing first makes the movement the same whatever the length of the
scroll, and clamps it at both ends for free.
Layers with low speed (sky: 10%) barely move — they appear far away. Layers
diff --git a/animations/01-scroll-based/scroll-trigger/README.md b/animations/01-scroll-based/scroll-trigger/README.md
index 0e3bc795..90391950 100644
--- a/animations/01-scroll-based/scroll-trigger/README.md
+++ b/animations/01-scroll-based/scroll-trigger/README.md
@@ -37,12 +37,12 @@ if (s !== prev[i]) {
}
```
-Scrubbing uses the same scroll position, normalised to `0–1` and clamped, then applied directly to transforms. Because it is clamped rather than gated on the active state, it resolves to 0 before its window and 1 after it — so a zone you skipped past still ends up in its finished state. The window belongs to the piece that animates (the square, the row of dots), not to the zone around it: here a zone is nearly a box tall and centres its content, so a window keyed to the zone's top would run before the piece could be seen:
+Scrubbing uses the same scroll position, normalized to `0–1` and clamped, then applied directly to transforms. Because it is clamped rather than gated on the active state, it resolves to 0 before its window and 1 after it — so a zone you skipped past still ends up in its finished state. The window belongs to the piece that animates (the square, the row of dots), not to the zone around it: here a zone is nearly a box tall and centers its content, so a window keyed to the zone's top would run before the piece could be seen:
```js
-// follow window: 0 as the piece's centre passes 80% down the box, 1 at 25%
-// (centre: the middle of its layout box, measured against the stage and cached like the zone tops)
-const p = clamp((stage.scrollTop - (centre - 0.8 * viewport)) / (0.55 * viewport), 0, 1);
+// follow window: 0 as the piece's center passes 80% down the box, 1 at 25%
+// (mid: the middle of its layout box, measured against the stage and cached like the zone tops)
+const p = clamp((stage.scrollTop - (mid - 0.8 * viewport)) / (0.55 * viewport), 0, 1);
swatch.style.transform = `rotate(${p * 180}deg) scale(${lerp(1, 1.3, p)})`;
swatch.style.filter = `hue-rotate(${p * 120}deg)`;
```
@@ -61,7 +61,7 @@ const p = clamp((stage.scrollTop - top[i]) / (height[i] - viewport), 0, 1);
| Parameter | Default | Effect |
|-----------|---------|--------|
| Zone height | 90% of the box (zone 3: twice the box) | How much scrolling each zone takes |
-| Follow window | From 80% to 25% down the box | The square in zone 2 and the row of dots in zone 4 play while their own centre rises between these two lines, so each plays in full view |
+| Follow window | From 80% to 25% down the box | The square in zone 2 and the row of dots in zone 4 play while their own center rises between these two lines, so each plays in full view |
| Pinned span | Zone 3's height less one box | How long the card holds still; its three stages share it equally |
| Run-out | One box height | Space after the last zone, so it can finish and leave |
@@ -69,7 +69,7 @@ const p = clamp((stage.scrollTop - top[i]) / (height[i] - viewport), 0, 1);
- **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-position arithmetic is right for scrubbing. This demo derives both from scroll position so the two stay in lockstep — with IO the callback and the scrub can disagree by a frame.
-- **Anchor the scrub to where the section *enters*, not to where it reaches the top.** Measuring progress as `scrollTop − zoneTop` keeps it at zero until the section's top has climbed all the way to the top of the viewport — by which point the reader has watched a full screen of it sit motionless, and the animation only plays as it leaves. That reads as a broken or badly late trigger. A common GSAP setting, `start: "top 80%"` / `end: "top 20%"`, begins just after the section appears and finishes as it settles; here that moved each trigger roughly 0.8 of a viewport earlier. Anchor it to the piece that animates, too: a zone that is nearly a box tall and centres its content puts the piece half a box below the zone's top, so the demo uses `start: "center 80%"` / `end: "center 25%"` on the square and on the row of dots, and the animation plays where it can be seen.
+- **Anchor the scrub to where the section *enters*, not to where it reaches the top.** Measuring progress as `scrollTop − zoneTop` keeps it at zero until the section's top has climbed all the way to the top of the viewport — by which point the reader has watched a full screen of it sit motionless, and the animation only plays as it leaves. That reads as a broken or badly late trigger. A common GSAP setting, `start: "top 80%"` / `end: "top 20%"`, begins just after the section appears and finishes as it settles; here that moved each trigger roughly 0.8 of a viewport earlier. Anchor it to the piece that animates, too: a zone that is nearly a box tall and centers its content puts the piece half a box below the zone's top, so the demo uses `start: "center 80%"` / `end: "center 25%"` on the square and on the row of dots, and the animation plays where it can be seen.
- **`offsetTop` is not in the scroll container's coordinate space.** It is measured from the nearest *positioned* ancestor, which for a plain `overflow: scroll` panel is usually `body` — so it includes every pixel of page chrome above the container, while `scrollTop` starts at zero inside it. Comparing them directly put every trigger here 109px late. Measure the zone against the container's own box instead.
- **Prime the state before firing callbacks.** Comparing the first frame's state against a `null` starting value manufactures events that never happened: zone 1 would fire `onEnterBack` and zones 2–4 `onLeaveBack` before any scrolling. Record the initial state on the first pass and only emit transitions after that.
- **Evaluate every trigger each frame, not just the active ones.** Updating a zone only while it is active leaves whatever value it happened to stop on — jump past a zone and its scrub never runs at all, and scrolling back to the top left the pinned card still reading "Step 3 of 3". Clamped progress resolves to 0 before a zone and 1 after it, so both ends settle correctly on their own.
diff --git a/animations/01-scroll-based/scrollytelling/README.md b/animations/01-scroll-based/scrollytelling/README.md
index 855d8278..2ee05d47 100644
--- a/animations/01-scroll-based/scrollytelling/README.md
+++ b/animations/01-scroll-based/scrollytelling/README.md
@@ -31,14 +31,14 @@ Reads are throttled with a `requestAnimationFrame` gate (`ticking`) so the scrol
|-----------|---------|--------|
| Reading line | 42% down the box | A chapter becomes current once its top passes this line; a higher line changes chapters later, a lower one sooner |
| Chapter height | At least 90% of the box | How much scrolling each chapter takes; taller chapters make slower, finer blends |
-| Number of chapters | 6 | Each chapter adds its colours and its depth to the blend |
+| Number of chapters | 6 | Each chapter adds its colors and its depth to the blend |
## Production notes
- **Fractional, not stepped**: the value that makes scrollytelling feel smooth is the decimal progress between chapters. If you only switch on integer chapter changes, you get a slideshow — interpolate everything you can.
- **Sticky visual, scrolling text**: the pattern is a `position: sticky` visual beside taller text columns. This is cheaper and more robust than JS-pinning; let CSS hold the visual in place.
- **Throttle reads**: `getBoundingClientRect` in a scroll handler forces layout. The rAF gate here keeps that to once per frame; on heavier visuals, cache rects and only recompute on resize.
- **Color interpolation**: blending hex colors requires parsing to RGB channels and lerping each — CSS won't tween `background` mid-value on its own, which is why this is done in JS.
-- **Reduced motion**: nothing here moves on its own; the colours and the depth follow the reader's scrolling, so there is nothing to switch off. A CSS transition on the porthole's gradient would not help anyway: gradients cannot be transitioned, which is why the blend is worked out in JavaScript.
+- **Reduced motion**: nothing here moves on its own; the colors and the depth follow the reader's scrolling, so there is nothing to switch off. A CSS transition on the porthole's gradient would not help anyway: gradients cannot be transitioned, which is why the blend is worked out in JavaScript.
- **Library equivalents**: Scrollama is the standard vanilla library for the "sticky graphic + scrolling steps" layout; GSAP ScrollTrigger with `scrub` handles the interpolation; Framer Motion's `useScroll` + `useTransform` map scroll progress to any animated value in React.
## See also
diff --git a/animations/03-page-transitions/dissolve/README.md b/animations/03-page-transitions/dissolve/README.md
index ec4fb279..66ec6ff7 100644
--- a/animations/03-page-transitions/dissolve/README.md
+++ b/animations/03-page-transitions/dissolve/README.md
@@ -27,7 +27,7 @@ function getDelays(n, style) {
return (r + c) / (2 * (n - 1));
});
}
- // radial: tile-centre distance, normalised so the corners land at 1
+ // radial: tile-center distance, normalized so the corners land at 1
return Array.from({length: total}, (_, i) => {
const r = Math.floor(i / n) - (n - 1) / 2, c = i % n - (n - 1) / 2;
return Math.sqrt(r * r + c * c) / (Math.SQRT2 * (n - 1) / 2);
diff --git a/animations/03-page-transitions/shared-element-transition/README.md b/animations/03-page-transitions/shared-element-transition/README.md
index 689623cb..061d2a36 100644
--- a/animations/03-page-transitions/shared-element-transition/README.md
+++ b/animations/03-page-transitions/shared-element-transition/README.md
@@ -45,7 +45,7 @@ The real grid fades out while the copy travels, and the detail body fades in sli
## Production notes
- **Read then write** — batch all `getBoundingClientRect()` reads before you touch styles. Interleaving reads and writes causes layout thrashing that stutters the animation.
-- **The clone is `position:fixed`**, so it moves in viewport coordinates and ignores the scroll and layout of the pages underneath it. It moves with `transform` alone (a shift and a scale), so the browser lays nothing out while it travels; only its corners are repainted. A scaled copy stretches what is inside it, which suits a picture or a colour but not text.
+- **The clone is `position:fixed`**, so it moves in viewport coordinates and ignores the scroll and layout of the pages underneath it. It moves with `transform` alone (a shift and a scale), so the browser lays nothing out while it travels; only its corners are repainted. A scaled copy stretches what is inside it, which suits a picture or a color but not text.
- **Fixed positioning uses viewport coordinates**, which is why the demo reads `getBoundingClientRect()` directly. If your clone lives inside a transformed or scrolled ancestor, offsets must be adjusted.
- **Reduced motion** skips the clone entirely and snaps the detail view in.
- **Library equivalents**: the View Transitions API does this natively by giving both elements the same `view-transition-name`. Framer Motion's `layoutId` and shared `<motion.*>` elements automate FLIP; GSAP's Flip plugin offers the same measure-invert-play primitive.
diff --git a/animations/04-micro-interactions/modal-expand/README.md b/animations/04-micro-interactions/modal-expand/README.md
index 1d445cb4..bebf296b 100644
--- a/animations/04-micro-interactions/modal-expand/README.md
+++ b/animations/04-micro-interactions/modal-expand/README.md
@@ -18,7 +18,7 @@ On click, measure the button's position with `getBoundingClientRect()`, then com
function openModal(btn) {
const sr = stage.getBoundingClientRect();
const br = btn.getBoundingClientRect();
- // The button's centre, relative to the stage
+ // The button's center, relative to the stage
const bx = br.left + br.width / 2 - sr.left;
const by = br.top + br.height / 2 - sr.top;
// The same point, relative to the modal's laid-out corner (offsetLeft/Top ignore its scale)
@@ -36,7 +36,7 @@ function openModal(btn) {
.modal {
position: absolute;
- inset: 0; margin: auto; /* centred without a transform */
+ inset: 0; margin: auto; /* centered without a transform */
width: clamp(240px, 55%, 320px); height: fit-content;
transform: scale(var(--start-scale));
opacity: 0;
diff --git a/animations/06-3d-advanced/image-distortion-hover/README.md b/animations/06-3d-advanced/image-distortion-hover/README.md
index 8eabcdf9..b0283c66 100644
--- a/animations/06-3d-advanced/image-distortion-hover/README.md
+++ b/animations/06-3d-advanced/image-distortion-hover/README.md
@@ -66,7 +66,7 @@ In the demo the pattern stands still, as a real image would: its time value stay
## Production notes
- **Real images**: replace the procedural `pattern()` function with `texture2D(uTexture, distortedUV)`. Load images into WebGL via `gl.texImage2D()` from an `<img>` or `ImageBitmap`. Same-origin policy applies — external image URLs need CORS headers.
- **`CLAMP_TO_EDGE`**: set the texture's wrap mode to `gl.CLAMP_TO_EDGE` (both `TEXTURE_WRAP_S` and `TEXTURE_WRAP_T`) so UV values outside [0,1] don't tile or mirror at the image border when distortion pushes UVs out of range.
-- **Pointer, not mouse**: bind `pointermove`/`pointerdown` rather than `mousemove`, or the effect never fires on a phone. The cursor position must be converted to backing-store pixels (multiply by the device pixel ratio used for the canvas) before it reaches the shader, or the distortion centre drifts away from the finger on high-DPI screens.
+- **Pointer, not mouse**: bind `pointermove`/`pointerdown` rather than `mousemove`, or the effect never fires on a phone. The cursor position must be converted to backing-store pixels (multiply by the device pixel ratio used for the canvas) before it reaches the shader, or the distortion center drifts away from the finger on high-DPI screens.
- **Backing store and DPR**: size the canvas to `clientWidth * dpr` and call `gl.viewport()` after every resize. Uncapped DPR is expensive for a fullscreen fragment shader — this demo caps it at 2, and at 1.5 on phones. Resizing clears the drawing buffer, so a demo that is not drawing every frame (this one stops at rest) has to repaint after a resize or it goes black.
- **Context loss**: a GPU reset or a restored tab fires `webglcontextlost`. Without a listener (and a `preventDefault()` so `webglcontextrestored` follows) the canvas dies permanently. Shaders, buffers and uniform locations all have to be rebuilt on restore.
- **CSS-only alternative**: CSS `filter: blur()` and `transform: translate()` on pseudo-elements can approximate push distortion for a single element at low intensity. WebGL is needed for per-pixel wave and liquid effects.
diff --git a/animations/06-3d-advanced/morphing-blob/README.md b/animations/06-3d-advanced/morphing-blob/README.md
index 5cc3f953..fb87e413 100644
--- a/animations/06-3d-advanced/morphing-blob/README.md
+++ b/animations/06-3d-advanced/morphing-blob/README.md
@@ -66,7 +66,7 @@ lets the droplet close 0.03 of the gap in every 1/60 s instead of 0.09.
The pointer's position is turned into the drawing's own units with the SVG's screen
matrix (`svg.getScreenCTM().inverse()`), so the droplet stays under the pointer
-however the SVG is scaled and centred, also beside the drawing on a wide stage. The
+however the SVG is scaled and centered, also beside the drawing on a wide stage. The
`viewBox` is a 360-unit box around the blob's middle (`20 20 360 360`) with
`preserveAspectRatio="xMidYMid meet"`: the circles wander up to about 190 units from
the middle, so the box shows them almost always, and the whole box fits whatever the
@@ -80,7 +80,7 @@ shape of the stage.
| Speed | Normal | How fast the circles drift: slow is 0.6, normal 1 and fast 1.6 times |
## Production notes
-- **Filter performance is the gotcha.** SVG filters rasterise the filter region every frame on the CPU/GPU compositor; a large blurred area over a big viewport can drop frames on mobile. Keep the filtered `<g>` region as small as the design allows, cap `stdDeviation`, and reduce blob count on small screens. Test on a mid-range phone, not just desktop.
+- **Filter performance is the gotcha.** SVG filters rasterize the filter region every frame on the CPU/GPU compositor; a large blurred area over a big viewport can drop frames on mobile. Keep the filtered `<g>` region as small as the design allows, cap `stdDeviation`, and reduce blob count on small screens. Test on a mid-range phone, not just desktop.
- **Safari and blur units.** `stdDeviation` is in user (viewBox) units, not pixels — the visual blur scales with your `viewBox`, so pin the viewBox size and let CSS scale the SVG rather than resizing the viewBox.
- **Time, not frames**: easing that closes a fixed share of the gap on every frame follows the screen's refresh rate. Scale the share by the time since the last frame, as above, and cap that time (this demo uses 50 ms) so a tab that comes back does not lurch.
- **`will-change: transform`** on the SVG element can promote it to its own layer and smooth things out, but watch memory on low-end devices.
diff --git a/animations/06-3d-advanced/parallax-3d-tilt/README.md b/animations/06-3d-advanced/parallax-3d-tilt/README.md
index aa5f9f99..5bc99183 100644
--- a/animations/06-3d-advanced/parallax-3d-tilt/README.md
+++ b/animations/06-3d-advanced/parallax-3d-tilt/README.md
@@ -12,7 +12,7 @@ A 3D tilt makes a flat card lean toward the pointer, as if you were looking at a
- NFT and gaming UIs where the tactile metaphor matches the product
## How it works
-`perspective` must be set on the **parent**, not the card. The card's `rotateX`/`rotateY` are computed from the cursor's position relative to the card's centre, normalized to ±0.5, then scaled by MAX, so the card leans MAX/2 at its edges.
+`perspective` must be set on the **parent**, not the card. The card's `rotateX`/`rotateY` are computed from the cursor's position relative to the card's center, normalized to ±0.5, then scaled by MAX, so the card leans MAX/2 at its edges.
Bind **pointer** events, not mouse events — the same handler then covers mouse, pen and touch:
diff --git a/animations/06-3d-advanced/volumetric-smoke/README.md b/animations/06-3d-advanced/volumetric-smoke/README.md
index 0c37a66a..d8a70148 100644
--- a/animations/06-3d-advanced/volumetric-smoke/README.md
+++ b/animations/06-3d-advanced/volumetric-smoke/README.md
@@ -74,7 +74,7 @@ Wherever `src` has faded to almost nothing the function returns before the noise
## Production notes
- **Precision**: the `sin`-based hash multiplies by 43758.5, which overflows the usable range of a 16-bit `mediump` float and collapses the noise to flat blocks on many mobile GPUs. Request `highp` in the fragment shader (guarded by `GL_FRAGMENT_PRECISION_HIGH`) or swap the hash for an integer-free variant with a smaller multiplier.
-- **Mobile cost**: this is fill-rate bound — every fragment runs up to `steps x (fbm + 3 shadow taps)`, so the demo trims it three ways. `smokeDensity` returns before the noise wherever the plume has faded out. The backing store is capped at about 65,000 pixels and the browser scales it up to the stage, which suits soft smoke; it never exceeds 1 CSS pixel per fragment either. On phones (screens 600px wide or less, or 500px tall or less when held sideways) the backing store is also at most 0.75 of the stage and the march at most 48 steps. Honouring a 3x phone DPR would multiply the cost ninefold.
+- **Mobile cost**: this is fill-rate bound — every fragment runs up to `steps x (fbm + 3 shadow taps)`, so the demo trims it three ways. `smokeDensity` returns before the noise wherever the plume has faded out. The backing store is capped at about 65,000 pixels and the browser scales it up to the stage, which suits soft smoke; it never exceeds 1 CSS pixel per fragment either. On phones (screens 600px wide or less, or 500px tall or less when held sideways) the backing store is also at most 0.75 of the stage and the march at most 48 steps. Honoring a 3x phone DPR would multiply the cost ninefold.
- **Context loss**: a GPU reset, a backgrounded tab on mobile, or a driver hiccup fires `webglcontextlost`. Without a listener the canvas goes permanently black with no error. Preventing the default event and rebuilding shaders and buffers on `webglcontextrestored` is the production path; this demo takes the simpler route of stopping the loop and showing a message.
- **Step count vs quality**: each additional march step increases pixel cost linearly. 32 steps is generally sufficient for soft smoke; use 64 only for hero-quality renders. Add blue-noise dithering to random-offset each ray's start, breaking up banding artifacts at low step counts. The offset has to be a fraction of a *full step* to help — jittering by a few thousandths of a unit is invisible.
- **Shadow rays**: the 3-step shadow march adds 3× extra density samples per lit pixel. Toggle off on low-end devices. For production, pre-compute a voxelized shadow map and sample it instead.
diff --git a/animations/07-ambient-background/plasma/README.md b/animations/07-ambient-background/plasma/README.md
index 4051a29e..cfcbd036 100644
--- a/animations/07-ambient-background/plasma/README.md
+++ b/animations/07-ambient-background/plasma/README.md
@@ -20,7 +20,7 @@ without any image or video.
## How it works
Each pixel gets a scalar value from a sum of sines — some of the position, some
-of time — and that value indexes a colour palette. Computing this per pixel at
+of time — and that value indexes a color palette. Computing this per pixel at
full resolution is expensive, so the field is rendered into a small offscreen
buffer (around 96–200px wide) and then scaled up onto the visible canvas with
image smoothing on. The upscale blur is free and actually helps the plasma look
@@ -31,7 +31,7 @@ softer.
const v = Math.sin(x*f + t) // horizontal wave
+ Math.sin(y*f + t*1.3) // vertical wave
+ Math.sin((x+y)*f*0.5 + t*0.7) // diagonal wave
- + Math.sin(dist*f + t*1.1); // radial wave from centre
+ + Math.sin(dist*f + t*1.1); // radial wave from center
const idx = ((v + 4) * 31.875) | 0; // v ∈ [-4,4] → palette index 0..255
data[o++] = lut[idx*3]; data[o++] = lut[idx*3+1]; data[o++] = lut[idx*3+2]; data[o++] = 255;
@@ -40,8 +40,8 @@ vctx.drawImage(buf, 0, 0, bw, bh, 0, 0, view.width, view.height); // scale up sm
```
The palette is a 256-entry lookup table built once with an Inigo Quilez cosine
-gradient, so changing palettes is just swapping the table — no per-pixel colour
-maths.
+gradient, so changing palettes is just swapping the table — no per-pixel color
+math.
## Key parameters
@@ -64,7 +64,7 @@ maths.
the size, so it is computed once; the row, column and diagonal sines change
with time, so they are computed once per frame for each row and column rather
than for every pixel, leaving one sine per pixel in the inner loop.
-- Do colour through a palette lookup table, not live RGB maths per pixel.
+- Do color through a palette lookup table, not live RGB math per pixel.
- Pause the `requestAnimationFrame` loop on `visibilitychange` when the tab is
hidden so a background tab does no work.
- Respect `prefers-reduced-motion`: render a single static frame and never start
diff --git a/animations/07-ambient-background/synthwave-grid/README.md b/animations/07-ambient-background/synthwave-grid/README.md
index ca96b62c..ba543125 100644
--- a/animations/07-ambient-background/synthwave-grid/README.md
+++ b/animations/07-ambient-background/synthwave-grid/README.md
@@ -32,7 +32,7 @@ last = now;
offset += speed * 0.02 * dt / (1000 / 60) * (slow ? 1 / 3 : 1);
```
-The glow is a canvas `shadowBlur` set to the grid colour; the sun is a clipped semicircle filled with a vertical gradient and striped with background-coloured gaps.
+The glow is a canvas `shadowBlur` set to the grid color; the sun is a clipped semicircle filled with a vertical gradient and striped with background-colored gaps.
## Key parameters
| Parameter | Default | Effect |