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.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
fix: clip Parallax 3D Tilt's card instead of hiding its overflow so it is no scroll box, and correct its README
matin03d1f97cff1a
diff --git a/animations/06-3d-advanced/parallax-3d-tilt/README.md b/animations/06-3d-advanced/parallax-3d-tilt/README.mdindex d9f4ffcc..581c6add 100644--- a/animations/06-3d-advanced/parallax-3d-tilt/README.md+++ b/animations/06-3d-advanced/parallax-3d-tilt/README.md@@ -10,7 +10,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 centre, 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:@@ -88,7 +88,7 @@ function step(now) { // t0 = the time of the first fra## Production notes- **Touch devices**: use Pointer Events (`pointerdown`/`pointermove`/`pointerleave`) plus `touch-action: none` and the effect works on touch for free — a drag tilts the card, a tap sets it once. Do not gate the effect on `@media (hover: hover)`: hybrid touchscreen laptops match it, and a phone with a paired mouse can match it too, so branching on the media query kills the interaction on real devices. If you need to branch, branch on the live `event.pointerType`.-- **`will-change: transform`**: add only during hover (`mouseenter`/`mouseleave`) to avoid permanent GPU layer allocation. Permanent `will-change` on many cards multiplies GPU memory use.+- **`will-change: transform`**: on a page with many tilt cards, add it only while the pointer is over a card (`pointerenter`/`pointerleave`), to avoid permanent GPU layer allocation: a permanent `will-change` on many cards multiplies GPU memory use. The demo has one card, so it keeps it on.- **VanillaTilt.js**: a zero-dependency library that handles this pattern with configurable tilt, glare, scale, and perspective. 2KB gzipped — use in production rather than hand-rolling.- **`overflow: hidden` flattens 3D**: any ancestor with `overflow` other than `visible` (or a `filter`, or `opacity < 1`) forces `transform-style` to its flat used value, so `translateZ` on a child silently does nothing. A card that clips its own contents therefore cannot also be a `preserve-3d` container — give it its own `perspective` so its inner depth layers still project, or move the clip to a wrapper outside the 3D chain.- **Performance**: `rotateX`/`rotateY` on a GPU-composited element runs at 60fps with no paint. Keep everything else that follows the pointer to `transform` and `opacity` as well: the demo moves its light as a layer (see Shine highlight) and leaves the card's shadow fixed in CSS, where it turns with the card. Rewriting a gradient or a `box-shadow` on every move repaints the whole card each frame, which shows on phones and adds up across a grid.diff --git a/animations/06-3d-advanced/parallax-3d-tilt/index.html b/animations/06-3d-advanced/parallax-3d-tilt/index.htmlindex bdeabc1e..25e80ba1 100644--- a/animations/06-3d-advanced/parallax-3d-tilt/index.html+++ b/animations/06-3d-advanced/parallax-3d-tilt/index.html@@ -27,13 +27,13 @@/* Card */.tilt-card{width:clamp(240px,40%,340px);height:min(240px,86%);- border-radius:16px;position:relative;overflow:hidden;+ border-radius:16px;position:relative;overflow:hidden;overflow:clip;background:linear-gradient(135deg,#0d2040,#1a3060);border:1px solid rgba(255,255,255,.15);box-shadow:0 20px 60px rgba(0,0,0,.6);- /* overflow:hidden above flattens transform-style:preserve-3d, so the depth- layers get their own local perspective instead. The card's own rotation is- projected by the perspective on .stage, never by a perspective() here. */+ /* The overflow clip above is overflow:hidden first, then overflow:clip where supported (clip leaves no scroll box for a drag to+ move). The card is not a preserve-3d container, which hidden would flatten anyway, so the depth layers get their own local+ perspective instead. The card's own rotation is projected by the perspective on .stage, never by a perspective() here. */perspective:var(--perspective);transform:rotateX(0deg) rotateY(0deg) scale(1);transition:transform var(--reset-dur) ease;diff --git a/docs/superpowers/plans/2026-09-29-3d-content.md b/docs/superpowers/plans/2026-09-29-3d-content.mdindex 7b5b81f0..b8104452 100644--- a/docs/superpowers/plans/2026-09-29-3d-content.md+++ b/docs/superpowers/plans/2026-09-29-3d-content.md@@ -286,7 +286,7 @@ None: leave out the `details.hb-options` block.- **Sequence:** `onMove(e)` becomes `tilt(x, y)` (x and y from −0.5 to 0.5) plus a small `onMove(e)` that works out x and y from the event and calls it. `tilt()` keeps the last x and y it was given (Show me starts from them), and `onLeave()` sets them back to 0. `onMove()` holds x and y between −0.5 and 0.5 (`edge()`): a finger dragged off the card keeps sending its moves to the card, and without the hold the card would lean without limit. Apart from the next bullet, everything else runs as today: `pointerdown` and `pointermove` on the card tilt it, and `pointerleave` and `pointercancel` call `onLeave()`.- **Only `transform` and `opacity` change while the card follows the pointer, a finger or Show me (fix round 1).** CLAUDE.md's rule "transform and opacity only — never animate `box-shadow`" governs over "as today" (the coordinator's ruling for this page, following the one on Task 7 that CLAUDE.md's rules govern over the sheet). Today's `tilt()` wrote `card.style.boxShadow` and rewrote the shine's gradient on every frame, and the shadow was part of the card's transition; either repaints the whole card. A trace of 1.5 s of Show me (phone stage, 375×812 at pixel ratio 2) showed 183 paint events and 98 to 135 raster tasks (about 250 ms of raster time); after the change it shows 4 paint events and 16 raster tasks (about 10 to 18 ms), and on a 1280×800 stage 4 paints against 181 to 185.- The card keeps its resting CSS shadow (`0 20px 60px rgba(0,0,0,.6)`), which turns with the card. Both writes to `boxShadow` go (`tilt()` and `onLeave()`), and the transition is `transform var(--reset-dur) ease` only.- - The shine is one fixed gradient on a layer of its own: `.card-shine{position:absolute;left:0;top:0;width:var(--shine-d,0);height:var(--shine-d,0);margin:calc(var(--shine-d,0px) / -2) 0 0 calc(var(--shine-d,0px) / -2);background:radial-gradient(circle closest-side,rgba(255,255,255,.18) 0%,transparent 65%);opacity:0;pointer-events:none;transition:opacity .3s;will-change:transform}`, a square twice as wide as the card's diagonal with its middle on the card's top left corner (the card's `overflow:hidden` clips it). `tilt()` reads `W = card.clientWidth` and `H = card.clientHeight` before it writes the card's transform, sets `--shine-d` (`D = 2*Math.hypot(W,H)`) on the card only when it changes, and moves the layer with `shine.style.transform = translate((x+.5)*W px, (y+.5)*H px) scale(2*R/D)`, where `R = Math.hypot((.5+Math.abs(x))*W, (.5+Math.abs(y))*H)` is the radius today's gradient has (a `circle` reaches the farthest corner). The Shine switch, `onLeave()` and the reduced-motion rule still work on the shine's `opacity`.+ - The shine is one fixed gradient on a layer of its own: `.card-shine{position:absolute;left:0;top:0;width:var(--shine-d,0);height:var(--shine-d,0);margin:calc(var(--shine-d,0px) / -2) 0 0 calc(var(--shine-d,0px) / -2);background:radial-gradient(circle closest-side,rgba(255,255,255,.18) 0%,transparent 65%);opacity:0;pointer-events:none;transition:opacity .3s;will-change:transform}`, a square twice as wide as the card's diagonal with its middle on the card's top left corner (the card's overflow clip clips it: `overflow:hidden;overflow:clip`, hidden first for a browser without clip, and clip leaves the card no scroll box, so a drag that selects text cannot move the 376×326px of hidden range the card's contents and orbs span, against the card's 338×238px). `tilt()` reads `W = card.clientWidth` and `H = card.clientHeight` before it writes the card's transform, sets `--shine-d` (`D = 2*Math.hypot(W,H)`) on the card only when it changes, and moves the layer with `shine.style.transform = translate((x+.5)*W px, (y+.5)*H px) scale(2*R/D)`, where `R = Math.hypot((.5+Math.abs(x))*W, (.5+Math.abs(y))*H)` is the radius today's gradient has (a `circle` reaches the farthest corner). The Shine switch, `onLeave()` and the reduced-motion rule still work on the shine's `opacity`.- The card and the light look as before. Against the page as it was (shadow and gradient written every frame), at eight poses (two corners, the middle and five others), three pairs of settings (Medium and Medium, Large and Strong, Small and Subtle) and stages of 1280×800, 375×812 (pixel ratio 2) and 1280×590, no pixel of the stage differs by more than 27 levels of a channel, the mean difference is under 1.1 levels, and at most 0.45% of the pixels differ by more than 8 levels. Those pixels lie within 2px of the card's edge or outside it, where the edge blends with the shadow just outside it (in 36 pictures, none deeper inside the card differs by more than 8 levels): at the middle pose the old shadow was centred under the card and the CSS one falls 20px below it.- **Reduced motion:** Show me does not run on arrival (the shared script). The demo's reduced-motion rule loses `transform:none!important` on the card and the orbs and `opacity:0!important` on the shine, which would stop Show me and the visitor's own tilt. What stays is `.tilt-card{transition:none!important}` and `.card-shine{transition:none!important}`, so the card snaps flat when the pointer leaves instead of easing back.- **Stage font:** site font. `.card-h` drops Georgia and the italic and gets `font-weight:700`. `.card-over` gets 11px, `font-weight:600` (was 9px) and `rgba(255,255,255,.7)` (was .4, which measures 2.3 to 3.8:1); `.card-sub` gets 13px and `rgba(255,255,255,.9)` (was 11px at .55) with `text-wrap:pretty`, so the phone card does not leave "it." alone on a third line. The first choice for `.card-sub`, .72, measured 3.6:1 with the pointer beside the purple orb (its glow and the light both under the words), 4.44:1 beside the blue orb and 5.1:1 at rest; .9, with the purple orb at `rgba(210,168,255,.2)` (was .25), holds at least 4.95:1 for the card line, 5.2:1 for the over-line and 7.4:1 for the title in every pose measured.