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.

fix: redraw Zoom Into Image's scene so the moon and lake show on laptops

matin0594f6fb7a9e
diff --git a/animations/01-scroll-based/zoom-into-image/README.md b/animations/01-scroll-based/zoom-into-image/README.md
index 0a07d8d3..a015863e 100644
--- a/animations/01-scroll-based/zoom-into-image/README.md
+++ b/animations/01-scroll-based/zoom-into-image/README.md
@@ -20,24 +20,26 @@ const radius = lerp(brStart, 0, p); // 16px → 0 (corners square off)
zoomImg.style.clipPath = `inset(${inset.toFixed(2)}% round ${radius.toFixed(1)}px)`;
-caption.style.opacity = p > 0.88 ? ((p - 0.88) / 0.12).toFixed(3) : '0';
+const cap = p > 0.88 ? ((p - 0.88) / 0.12).toFixed(3) : '0';
+caption.style.opacity = cap;
+frameBorder.style.opacity = (1 - cap).toFixed(3); // the starting-frame outline gives way to the caption
```
-Clipping rather than scaling is the crucial choice: `clip-path` reveals more of the *existing* image at full resolution, so nothing blurs or pixelates the way a `transform: scale()` zoom would. The caption fades in only over the final 12% of the scroll, once the image is essentially full-bleed.
+Clipping rather than scaling is the crucial choice: `clip-path` reveals more of the *existing* image at full resolution, so nothing blurs or pixelates the way a `transform: scale()` zoom would. The caption fades in only over the final 12% of the scroll, once the image is essentially full-bleed, and the faint starting-frame outline fades out over the same stretch, so it never crosses the caption.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
| Starting window | Medium | How much of the picture shows at first: small is a window a fifth of the box wide, medium two fifths and large three fifths |
| Corners | Rounded | How round the window's corners are at the start: square, 16px or 32px; they straighten as the window opens |
-| Shows the starting frame | on | A faint outline stays where the window began, so you can see how far it has opened |
+| Shows the starting frame | on | A faint outline stays where the window began, so you can see how far it has opened; it fades out as the caption fades in |
## Production notes
- **Clip, don't scale**: `clip-path: inset()` reveals real pixels, keeping the image sharp at every step. A `scale()` zoom enlarges a fixed render and softens. Use clipping when the whole image is present and you're uncovering it.
- **`will-change: clip-path`**: set on the image so the browser prepares for the animating clip. Animating `clip-path` is compositor-friendly on modern engines but still benefits from the hint.
- **Sticky provides the pin**: the image holds still via `position: sticky` while the tall section scrolls; the clip is the only thing changing, which keeps the effect cheap.
- **`round` keyword**: `inset(x% round Ypx)` combines the crop and rounded corners in one property, so both animate together off a single progress value.
-- **Reduced motion**: under `prefers-reduced-motion` the CSS forces `clip-path: inset(0%)` and shows the caption immediately — the reader gets the final full image with no fly-in.
+- **Reduced motion**: under `prefers-reduced-motion` the CSS forces `clip-path: inset(0%)`, shows the caption immediately and hides the starting-frame outline — the reader gets the final full image with no fly-in.
- **Library equivalents**: GSAP ScrollTrigger with `scrub` tweening `clipPath` is the direct equivalent and adds easing; Framer Motion animates the `clipPath` style off a `useTransform` of scroll progress in React.
## See also
diff --git a/animations/01-scroll-based/zoom-into-image/index.html b/animations/01-scroll-based/zoom-into-image/index.html
index 236902d1..25b10254 100644
--- a/animations/01-scroll-based/zoom-into-image/index.html
+++ b/animations/01-scroll-based/zoom-into-image/index.html
@@ -28,7 +28,7 @@
.spacer{height:60cqh;display:flex;align-items:center;justify-content:center;padding:0 24px;font-size:13px;letter-spacing:.1em;color:#8a8a92;text-align:center}
#zoom-section{height:250cqh;position:relative}
#zoom-sticky{position:sticky;top:0;height:100cqh;display:flex;align-items:center;justify-content:center;overflow:hidden}
- /* The outline where the window began; the Shows the starting frame switch fades it */
+ /* The outline where the window began: the Shows the starting frame switch fades it, and it gives way to the caption */
#frame{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;pointer-events:none;opacity:1;transition:opacity .4s}
.frame-border{position:absolute;border:1px solid rgba(255,255,255,.15);border-radius:calc(var(--br-start) * 1px + 2px);pointer-events:none}
/* The landscape image (clip-path drives the reveal) */
@@ -38,7 +38,7 @@
#caption{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;padding-bottom:40px;opacity:0;pointer-events:none;background:linear-gradient(transparent 60%,rgba(0,0,0,.6))}
#caption .cap-title{font-size:clamp(18px,3vw,28px);font-weight:700;letter-spacing:3px;text-transform:uppercase;text-align:center}
#caption .cap-sub{font-size:11px;opacity:.6;margin-top:6px;letter-spacing:2px;text-transform:uppercase}
- @media(prefers-reduced-motion:reduce){#zoom-img{clip-path:inset(0% round 0px)!important}#caption{opacity:1!important}}
+ @media(prefers-reduced-motion:reduce){#zoom-img{clip-path:inset(0% round 0px)!important}#caption{opacity:1!important}.frame-border{opacity:0!important}}
</style>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=4">
<script src="../../../assets/js/demo-page.js?v=4" defer></script>
@@ -81,12 +81,13 @@
<stop offset="100%" stop-color="transparent"/>
</radialGradient>
</defs>
+ <!-- The moon, the mountains and the lake sit in the band y 192-408, the part of the drawing a wide box keeps -->
<!-- Sky -->
- <rect width="800" height="420" fill="url(#sky-grad)"/>
+ <rect width="800" height="345" fill="url(#sky-grad)"/>
<!-- Moon glow -->
- <circle cx="600" cy="90" r="80" fill="url(#moon-glow)"/>
+ <circle cx="600" cy="218" r="70" fill="url(#moon-glow)"/>
<!-- Moon -->
- <circle cx="600" cy="90" r="28" fill="#e8dca0" opacity=".92"/>
+ <circle cx="600" cy="218" r="24" fill="#e8dca0" opacity=".92"/>
<!-- Stars -->
<circle cx="80" cy="40" r="1.2" fill="white" opacity=".9"/>
<circle cx="220" cy="70" r="1" fill="white" opacity=".7"/>
@@ -94,25 +95,28 @@
<circle cx="460" cy="55" r="1" fill="white" opacity=".6"/>
<circle cx="150" cy="120" r="1" fill="white" opacity=".5"/>
<circle cx="700" cy="40" r="1.2" fill="white" opacity=".8"/>
- <circle cx="760" cy="130" r="1" fill="white" opacity=".4"/>
- <circle cx="50" cy="180" r="1" fill="white" opacity=".6"/>
+ <circle cx="90" cy="205" r="1.2" fill="white" opacity=".8"/>
+ <circle cx="250" cy="226" r="1" fill="white" opacity=".6"/>
+ <circle cx="380" cy="199" r="1.4" fill="white" opacity=".8"/>
+ <circle cx="470" cy="232" r="1" fill="white" opacity=".5"/>
+ <circle cx="740" cy="236" r="1" fill="white" opacity=".6"/>
<!-- Distant mountains -->
- <polygon points="0,420 150,260 280,330 420,220 560,300 680,230 800,290 800,420" fill="#0a1a30" opacity=".9"/>
+ <polygon points="0,345 150,265 280,300 420,245 560,285 680,250 800,280 800,345" fill="#0a1a30" opacity=".9"/>
<!-- Near mountains -->
- <polygon points="0,420 80,330 180,360 300,300 420,340 520,290 640,320 750,280 800,310 800,420" fill="#060e1c"/>
+ <polygon points="0,345 80,300 180,315 300,285 420,305 520,280 640,295 750,275 800,290 800,345" fill="#060e1c"/>
<!-- Reflection base -->
- <rect y="420" width="800" height="180" fill="url(#water-grad)"/>
+ <rect y="345" width="800" height="255" fill="url(#water-grad)"/>
<!-- Water shimmer lines -->
- <line x1="0" y1="440" x2="800" y2="440" stroke="rgba(255,255,255,.04)" stroke-width="1"/>
- <line x1="0" y1="460" x2="800" y2="460" stroke="rgba(255,255,255,.03)" stroke-width="1"/>
- <line x1="0" y1="485" x2="800" y2="485" stroke="rgba(255,255,255,.03)" stroke-width="1"/>
+ <line x1="0" y1="365" x2="800" y2="365" stroke="rgba(255,255,255,.04)" stroke-width="1"/>
+ <line x1="0" y1="385" x2="800" y2="385" stroke="rgba(255,255,255,.03)" stroke-width="1"/>
+ <line x1="0" y1="410" x2="800" y2="410" stroke="rgba(255,255,255,.03)" stroke-width="1"/>
<!-- Moon reflection -->
- <ellipse cx="600" cy="470" rx="18" ry="8" fill="#e8dca0" opacity=".25"/>
- <ellipse cx="600" cy="500" rx="12" ry="4" fill="#e8dca0" opacity=".12"/>
+ <ellipse cx="600" cy="372" rx="18" ry="8" fill="#e8dca0" opacity=".25"/>
+ <ellipse cx="600" cy="395" rx="12" ry="4" fill="#e8dca0" opacity=".12"/>
</svg>
</div>
- <div id="caption"><p class="cap-title">Through the Portal</p><p class="cap-sub">Keep scrolling</p></div>
<div id="frame"><div class="frame-border" style="inset:28%"></div></div>
+ <div id="caption"><p class="cap-title">Through the Portal</p><p class="cap-sub">Keep scrolling</p></div>
</div>
</div>
<div class="spacer">The page moves on ↓</div>
@@ -207,7 +211,7 @@
function update(){
ticking=false;
- // reduced motion: the CSS rule above shows the full picture and the caption, whatever the scroll position
+ // reduced motion: the CSS rule above shows the full picture and the caption and hides the outline, whatever the scroll position
if(motionMQ.matches)return;
const st=stage.scrollTop,stageH=stage.clientHeight;
const pinStart=zoomSec.offsetTop,budget=zoomSec.offsetHeight-stageH;
@@ -215,7 +219,9 @@
const inset=lerp(startPct,0,p);
const radius=lerp(brStart,0,p);
zoomImg.style.clipPath=`inset(${inset.toFixed(2)}% round ${radius.toFixed(1)}px)`;
- caption.style.opacity=p>0.88?((p-0.88)/0.12).toFixed(3):'0';
+ const cap=p>0.88?((p-0.88)/0.12).toFixed(3):'0';
+ caption.style.opacity=cap;
+ frameBorder.style.opacity=(1-cap).toFixed(3); // the starting-frame outline fades out as the caption fades in
}
stage.addEventListener('scroll',()=>{if(!ticking){requestAnimationFrame(update);ticking=true}},{passive:true});
diff --git a/docs/superpowers/plans/2026-09-29-scroll-content-part2.md b/docs/superpowers/plans/2026-09-29-scroll-content-part2.md
index 80a57fe4..6b606b34 100644
--- a/docs/superpowers/plans/2026-09-29-scroll-content-part2.md
+++ b/docs/superpowers/plans/2026-09-29-scroll-content-part2.md
@@ -501,9 +501,9 @@ The two lists below, A and B, were settled after both halves were reviewed. They
- **Step 1:** Scroll it · help line: default
- **Player bar:** Play · Back to top
- **Scroller:** the stage.
-- **What scrolling shows:** the cue "Scroll down ↓"; then the picture (a moonlit lake between mountains) reaches the top of the box and holds still while its window opens outward in step with the scroll, its rounded corners squaring off, until the picture fills the box. A faint outline stays where the window began. Over the last eighth of the opening, the caption "Through the Portal" fades in. Scrolling back closes the window again. Then the cue "The page moves on ↓" scrolls in.
+- **What scrolling shows:** the cue "Scroll down ↓"; then the picture (a moonlit lake between mountains: a round full moon, two ranges of dark mountains and the lake with the moon's reflection, all in view on every box from a 3.7:1 laptop box to a phone; see the recomposed drawing under Stage) reaches the top of the box and holds still while its window opens outward in step with the scroll, its rounded corners squaring off, until the picture fills the box. A faint outline stays where the window began, and fades out over the last eighth of the opening while the caption "Through the Portal" fades in, so the outline never crosses the caption text. Scrolling back closes the window again. Then the cue "The page moves on ↓" scrolls in.
- **Scroll distance and Play:** a 60cqh lead-in, the 250cqh section with its sticky frame 100cqh tall, and a 60cqh lead-out: 2.7 box heights of scrolling. The window opens during 1.5 of them, about 3.3 of Play's six seconds.
-- **Reduced motion:** nothing scrolls by itself. As today, the full picture and its caption show from the start and do not change as the box scrolls (the demo's CSS rule and the `motionOk` early return stay).
+- **Reduced motion:** nothing scrolls by itself. As today, the full picture and its caption show from the start and do not change as the box scrolls (the demo's CSS rule and the `motionOk` early return stay). The starting-frame outline is hidden then (`.frame-border{opacity:0!important}` in the same rule): the caption is on from the start, and on a short box the outline would cross it.
- **Stage font:** site font. The caption title (`.cap-title`, today's `#caption h2`) uses `font-weight:700` (was `bold`).
- **Stage:**
- `.stage`: `position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d`, with `aria-label="A picture that opens up as you scroll"`. `position:relative` also makes the window start opening as soon as the picture reaches the top: today `zoomSec.offsetTop` is measured from the top of the page.
@@ -512,7 +512,15 @@ The two lists below, A and B, were settled after both halves were reviewed. They
- The picture's `svg` gets `role="img"` and `aria-label="A lake under a full moon, between dark mountains"`.
- The caption holds no heading (rule B13): `<h2>Through the Portal</h2><p>Scroll to exit</p>` becomes `<p class="cap-title">Through the Portal</p><p class="cap-sub">Keep scrolling</p>`. The `#caption h2` rule becomes `#caption .cap-title` and the `#caption p` rule becomes `#caption .cap-sub`, each with the same values (the small line stays 11px, a caption label).
- `#zoom-img` keeps `clip-path:inset(30% round 16px)` and the frame keeps `inset:28%`, which match the defaults.
- - Script: `update()` keeps the inset, radius and caption maths; the readout line goes, and the clip no longer checks the removed portal switch.
+ - **The outline gives way to the caption (Task 11 fix round 1, 2026-09-30).** The reviewer found the outline drawn over the caption text on short boxes (its bottom edge crosses the title at 258px and 325px with Medium, and the title or the small line with Large at 258px to 438px). `#frame` now comes before `#caption` in the DOM, so the caption is drawn over it, and `update()` sets `frameBorder.style.opacity` to 1 minus the caption's opacity, so the outline is gone once the caption is fully in (the switch's own `#frame` opacity and its 0.4s fade are untouched). Moving `#frame` alone was not enough: rendered, the line still ran along the title from behind.
+ - **The drawing is recomposed (Task 11 fix round 1, 2026-09-30; the owner's pick, option B).** Under `preserveAspectRatio="xMidYMid slice"` (kept) a wide box shows only the middle band of the 800×600 drawing: viewBox y 192–408 on a 958×258 box (3.7:1), y 164–436 on 958×325 and y 142–458 on 958×378. The old drawing had the moon at y 62–118 and the lake below y 420, so no laptop or desktop box ever showed the moon and at most a strip of lake, while the `aria-label` and the words above describe a lake under a full moon. The recomposition is a coordinate-only edit of the same drawing (same gradients, colours and shapes, and no stretching, so the moon stays round):
+ - the sky rect ends at y 345 (was 420); the moon and its glow move to `cy` 218 (was 90), the moon to `r` 24 (was 28) and the glow to `r` 70 (was 80);
+ - both mountain polygons stand on y 345 (was 420) with their heights halved: distant peaks at y 245–300 (were 220–330), near ones at y 275–315 (were 280–360);
+ - the water rect starts at y 345 (`height` 255); the shimmer lines are at y 365, 385 and 410 (were 440, 460 and 485); the reflection ellipses at `cy` 372 and 395 (were 470 and 500);
+ - the stars at (760,130) and (50,180) go, and five stars at (90,205), (250,226), (380,199), (470,232) and (740,236) fill the band; the other six stay.
+ - The moon (y 194–242) and the mountains (y 245–345) lie wholly inside y 192–408, and so does the top of the lake (y 345–408), so the widest box (3.7:1) keeps all three. The starting window still shows mountains at every setting.
+ - Measured in headless Chrome, fully open, box sizes inside the border, distances from the top edge of the box: 958×258 (1280×590): moon 57px across and round, 2px down; distant peaks 63px, near peaks 99px; lake 75px tall. 958×325 (1366×657): moon 35px down, lake 109px. 958×378 (1280×800): moon 62px down, lake 135px. 705×438 (768×1024): moon 42px across, lake 180px. 745×258 (a phone held sideways, 812×375): moon 45px across, lake 87px. 341×298 and 286×298 (phones): moon 24px across, lake 127px. The moon is a 1:1 circle at every size, both reflection ellipses are inside the box, and the caption never covers the moon. Under the starting window (Small / Medium / Large) the mountains fill 82–100% / 31–81% / 15–56% of what shows, at every size.
+ - Script: `update()` keeps the inset, radius and caption maths; the readout line goes, and the clip no longer checks the removed portal switch. It also sets the outline's fade, as above.
- Phone rules: none. Today's mobile block held only the stage height and the aside.
- `hb-dots`: no. Default height.
@@ -527,7 +535,7 @@ The two lists below, A and B, were settled after both halves were reviewed. They
| Setting | Control | Choices or range (value shown) | Default | Hint | Sets in the demo |
|---|---|---|---|---|---|
-| Shows the starting frame | Switch | on / off | on | A faint outline marks where the window began. | `frameEl.style.opacity`: `'1'` / `'0'` |
+| Shows the starting frame | Switch | on / off | on | A faint outline marks where the window began. | `frameEl.style.opacity`: `'1'` / `'0'` (the outline inside it also fades out with the caption, as under Stage) |
- **Removed:**
- The note, and the Section readout.
@@ -550,15 +558,15 @@ The two lists below, A and B, were settled after both halves were reviewed. They
|-----------|---------|--------|
| Starting window | Medium | How much of the picture shows at first: small is a window a fifth of the box wide, medium two fifths and large three fifths |
| Corners | Rounded | How round the window's corners are at the start: square, 16px or 32px; they straighten as the window opens |
- | Shows the starting frame | on | A faint outline stays where the window began, so you can see how far it has opened |
+ | Shows the starting frame | on | A faint outline stays where the window began, so you can see how far it has opened; it fades out as the caption fades in |
- **README See also:** the last link's text changes from "Parallax Depth of Field" to the page's real title.
- [Sticky Section](../sticky-section/) — the pinning this effect is built on
- [Scrub Animation](../scrub-animation/) — scroll position drives the movement, both ways
- [Cover Card to Fixed Header](../cover-card-to-fixed-header/) — a big cover changes shape as you scroll
- [Parallax Depth-of-Field](../parallax-depth-of-field/) — layers move and blur for depth as you scroll
-- **README How it works:** in the snippet, the three lines from `zoomImg.style.clipPath = portalTog.checked` to its `: ` alternative become one line: ``zoomImg.style.clipPath = `inset(${inset.toFixed(2)}% round ${radius.toFixed(1)}px)`;``. The rest is unchanged.
-- **README Production notes:** unchanged
+- **README How it works:** in the snippet, the three lines from `zoomImg.style.clipPath = portalTog.checked` to its `: ` alternative become one line: ``zoomImg.style.clipPath = `inset(${inset.toFixed(2)}% round ${radius.toFixed(1)}px)`;``. Fix round 1: the caption line becomes three lines that also fade the outline, `const cap = p > 0.88 ? ((p - 0.88) / 0.12).toFixed(3) : '0';`, `caption.style.opacity = cap;` and `frameBorder.style.opacity = (1 - cap).toFixed(3);` (with a short comment), and the sentence after the snippet adds ", and the faint starting-frame outline fades out over the same stretch, so it never crosses the caption". The rest is unchanged. No README line describes the drawing itself.
+- **README Production notes:** unchanged, except that the Reduced motion bullet now reads "shows the caption immediately and hides the starting-frame outline" (fix round 1).
- **Category line:** `01.19 · Scroll-Based`
- **Pager:** Previous: Section Wipe (`../section-wipe/`) · Next: Scroll Image Sequence (`../scroll-image-sequence/`)