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: move Cover Card's cover with transforms and reset it at once after a jump

matinb88b78c5ee7d
diff --git a/animations/01-scroll-based/cover-card-to-fixed-header/README.md b/animations/01-scroll-based/cover-card-to-fixed-header/README.md
index 7ad3eb2a..956a1e5f 100644
--- a/animations/01-scroll-based/cover-card-to-fixed-header/README.md
+++ b/animations/01-scroll-based/cover-card-to-fixed-header/README.md
@@ -28,11 +28,12 @@ const p = Math.min(1, Math.max(0, scrollTop / RANGE));
const e = easeOutCubic(p);
```
-Eight properties are then interpolated against `e` in a single
-`requestAnimationFrame` callback:
+The cover's visible height and seven other values are then worked out from `e`
+in a single `requestAnimationFrame` callback:
```js
-cover.style.height = lerp(FULL, 56, e) + 'px'; // FULL: 85% of the box's height
+const h = lerp(FULL, 56, e), d = FULL - h; // FULL: 85% of the box's height
+cover.style.transform = `translateY(${-d}px)`; // the cover keeps its full height and slides up
coverTitle.style.transform = `scale(${lerp(1, 13 / 26, e)})`;
coverBg.style.opacity = lerp(1, 0.12, e);
coverBg.style.filter = `blur(${lerp(0, 6, e)}px)`;
@@ -43,10 +44,12 @@ coverRule.style.opacity = e;
```
The title shrinks by `transform: scale()` with `transform-origin: left top`
-rather than by writing `font-size` — see the production note below. A
-`flex: 1` spacer inside the cover pushes content to the bottom at full
-height and compresses as height shrinks, so the title rises into header
-position on its own.
+rather than by writing `font-size` — see the production note below. Nothing is
+resized: the cover keeps its full height in the layout and slides up by what it
+has shrunk, and the article slides with it; the badge and the backdrop are moved
+back into the visible part, and once the cover is shorter than its text the text
+starts at the top of the bar. Back to top and Play from the end set the eased
+value at once.
## Key parameters
@@ -62,12 +65,10 @@ position on its own.
the header flickers. Scrubbing to a 0→1 value means every scroll position
has a well-defined, intentional appearance. Medium, Substack, and the NYT
app all use variants of this pattern.
-- **The height animation triggers layout.** Animating `height` forces the
- browser to recalculate layout on every frame. The production alternative:
- keep the outer container at a fixed height, set `overflow: hidden`, and
- animate `clip-path` (layout-free) or `transform: scaleY()` on the inner
- element with `transform-origin: top`. This demo prioritises readability
- over raw performance.
+- **Move the cover; never animate its `height`.** Writing `height` lays the page
+ out every frame. Keep the cover at full height, slide it and the content below
+ with `translateY()`, and squeeze the backdrop with `scaleY()` from its top
+ edge — as the demo does.
- **Turn off scroll anchoring.** This is the bug that bites everyone who builds a
collapsing header. When the cover shrinks, content above the viewport loses
height, so the browser "helpfully" adjusts `scrollTop` to keep what you are
@@ -75,6 +76,9 @@ position on its own.
which moves the scroll again — the collapse stalls partway and the scroll feels
like it is fighting you. `overflow-anchor: none` on the scroll container ends it.
Any scroll-driven animation that changes the size of in-flow content needs this.
+ This demo moves the cover with transforms, so scrolling never changes its
+ height; the rule stays as a guard for when the box is measured again after a
+ resize.
- **Ease the finished value, not the raw progress.** A mouse wheel arrives in
~100px jumps; with a 320px range that is a third of the animation per notch, and
easeOutCubic — slope 3 near zero — turns the first notch into 68% of the collapse.
diff --git a/animations/01-scroll-based/cover-card-to-fixed-header/index.html b/animations/01-scroll-based/cover-card-to-fixed-header/index.html
index 1c0881a7..58f5ef5b 100644
--- a/animations/01-scroll-based/cover-card-to-fixed-header/index.html
+++ b/animations/01-scroll-based/cover-card-to-fixed-header/index.html
@@ -25,16 +25,14 @@
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.stage{
position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d;
- /* The cover shrinking above the viewport makes scroll anchoring claw scrollTop
- back, which lowers progress, which re-grows the cover — a feedback loop that
- stalls the collapse partway. Any scroll-driven size change needs this off. */
+ /* Scroll anchoring stays off: a cover that changed its real height would fight the scroll (see the README) */
overflow-anchor:none;
}
.stage::-webkit-scrollbar{display:none}
.scene{position:relative}
- .cover{position:sticky;top:0;z-index:10;height:85cqh;overflow:hidden;background:#050e08}
- .cover-bg{position:absolute;inset:0;background:linear-gradient(150deg,#050e08,#0c2820,#060a10);will-change:opacity,filter}
+ .cover{position:sticky;top:0;z-index:10;height:85cqh;overflow:hidden;background:#050e08;will-change:transform}
+ .cover-bg{position:absolute;inset:0;transform-origin:top;background:linear-gradient(150deg,#050e08,#0c2820,#060a10);will-change:opacity,filter}
.cover-inner{position:relative;z-index:1;display:flex;flex-direction:column;height:100%;padding:0 24px 20px}
.cover-spacer{flex:1}
.cover-meta{font-size:11px;color:#5fa577;letter-spacing:1px;text-transform:uppercase;margin-bottom:8px}
@@ -51,7 +49,7 @@
.avatar-sm{width:16px;height:16px;border-radius:50%;flex-shrink:0;background:linear-gradient(135deg,#3fb950,#56d364)}
.chip-name{font-size:11px;color:#d1f7d6}
- .article-body{padding:28px 24px;max-width:600px}
+ .article-body{padding:28px 24px;max-width:600px;will-change:transform}
.article-body h3{font-size:12px;color:var(--ui-accent);letter-spacing:1px;text-transform:uppercase;margin:28px 0 10px}
.article-body p{font-size:14px;color:var(--ui-muted);line-height:1.75;margin-bottom:14px}
.article-body blockquote{border-left:2px solid var(--ui-accent);padding:8px 16px;margin:18px 0;font-size:15px;color:var(--ui-text)}
@@ -60,7 +58,7 @@
font-size:13px;color:#8a8a92;letter-spacing:.1em;text-align:center;padding:0 24px}
@media(max-width:600px){:root{--cover-min:64px}}
- @media(prefers-reduced-motion:reduce){.cover,.cover-title,.cover-bg,.header-chip{will-change:auto}}
+ @media(prefers-reduced-motion:reduce){.cover,.cover-title,.cover-bg,.header-chip,.article-body{will-change:auto}}
</style>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=4">
<script src="../../../assets/js/demo-page.js?v=4" defer></script>
@@ -98,7 +96,7 @@
</div>
</div>
<div class="cover-rule" id="cover-rule" aria-hidden="true"></div>
- <div class="header-chip" id="header-chip">
+ <div class="header-chip" id="header-chip" aria-hidden="true">
<div class="avatar-sm"></div>
<span class="chip-name">Matin M.</span>
</div>
@@ -192,6 +190,7 @@
const headerChip = $('header-chip'), coverRule = $('cover-rule'), stage = $('stage');
const scene = $('scene'), snapTog = $('snap-tog');
const article = document.querySelector('.article-body'), endCue = document.querySelector('.end-cue');
+ const coverInner = document.querySelector('.cover-inner'), spacer = document.querySelector('.cover-spacer'); let CONTENT = 0;
const motionMQ = window.matchMedia('(prefers-reduced-motion: reduce)');
// The full cover is 85% of the box and the slim one comes from a CSS variable that the phone rule
@@ -225,7 +224,8 @@
FULL = Math.round(stage.clientHeight * 0.85);
scene.style.minHeight = Math.max(FULL + article.offsetHeight, stage.clientHeight + 440) + 'px';
endCue.style.height = (FULL - MIN) + 'px';
- delete G.h; // the cover's height is written again with the new FULL
+ cover.style.height = FULL + 'px'; CONTENT = FULL - spacer.getBoundingClientRect().height;
+ delete G.h; // the cover's slide is written again with the new FULL and CONTENT
}
// Scroll progress -> collapse amount. Snapping at halfway and reduced motion snap by design.
@@ -236,7 +236,14 @@
// travel in one frame — easing raw progress instead lets easeOutCubic (slope 3
// near zero) re-amplify a wheel notch back into a jump.
function render(e) {
- set('h', q(lerp(FULL, MIN, e), .5), v => cover.style.height = v + 'px');
+ // The cover keeps its full height and slides up by what it has shrunk; the article slides with it, so no frame lays the page out
+ set('h', q(lerp(FULL, MIN, e), 1), v => {
+ const d = FULL - v;
+ cover.style.transform = article.style.transform = `translateY(${-d}px)`;
+ headerChip.style.transform = `translateY(${d}px)`;
+ coverBg.style.transform = `translateY(${d}px) scaleY(${v / FULL})`;
+ coverInner.style.transform = `translateY(${Math.max(0, CONTENT - v)}px)`;
+ });
set('bgOp', q(lerp(1, .12, e), .01), v => coverBg.style.opacity = v);
set('blur', q(lerp(0, 6, e), BLUR_STEP), v => coverBg.style.filter = v > 0 ? `blur(${v}px)` : 'none');
set('scale', q(lerp(1, 13 / 26, e), .002), v => coverTitle.style.transform = `scale(${v})`);
@@ -262,6 +269,8 @@
target = curveOf(clamp(stage.scrollTop / RANGE, 0, 1));
schedule();
}, { passive: true });
+ // Back to top, and Play starting again from the top, jump the box (the shared script moves it before the click reaches the document): the cover jumps with it
+ document.addEventListener('click', e => { if (e.target.closest('#btn-top,#btn-scroll')) { target = current = curveOf(clamp(stage.scrollTop / RANGE, 0, 1)); render(current); } });
function choices(id, pick) {
const buttons = document.querySelectorAll('#' + id + ' button');
diff --git a/docs/superpowers/plans/2026-09-29-scroll-content-part1.md b/docs/superpowers/plans/2026-09-29-scroll-content-part1.md
index 279f8885..5bd7847c 100644
--- a/docs/superpowers/plans/2026-09-29-scroll-content-part1.md
+++ b/docs/superpowers/plans/2026-09-29-scroll-content-part1.md
@@ -270,18 +270,18 @@ None: leave out the `details.hb-options` block.
- **Step 1:** Scroll it · help line: default
- **Player bar:** Play · Back to top
- **Scroller:** the stage.
-- **What scrolling shows:** an article page whose cover fills most of the box. As the box scrolls, the cover shrinks into a slim bar pinned at the top: the title scales down into the corner, the subtitle and date fade out first, the background dims and blurs, a thin line appears under the bar and the author's name fades into its corner. The article text then scrolls up under the bar, and a closing line fills the space after it. Scrolling back opens the cover again in reverse. Back to top, and Play restarting from the top, jump the box at once; the cover then eases open over a moment, as after a wheel jump.
+- **What scrolling shows:** an article page whose cover fills most of the box. As the box scrolls, the cover shrinks into a slim bar pinned at the top: the title scales down into the corner, the subtitle and date fade out first, the background dims and blurs, a thin line appears under the bar and the author's name fades into its corner. The article text then scrolls up under the bar, and a closing line fills the space after it. Scrolling back opens the cover again in reverse. Back to top, and Play restarting from the top, jump the box at once, and the cover jumps with it (a click on either button sets the eased value at once).
- **Scroll distance and Play:** the scene is as tall as the full cover plus the article (below): about 1.3 box heights of scrolling at 1280×800 (498px) and 2.4 on a phone (701px). At the default Shrink distance, Play spends about four of its six seconds shrinking the cover (under three on phones), then scrolls the article up and ends on the closing line, with the article's last line or so above it (15px of it at 1280×800, none in the 258px box).
- **Reduced motion:** nothing scrolls by itself. As today, the cover snaps between tall and slim at half the Shrink distance, with no easing (`snaps()` is true under reduced motion). The CSS rule for `will-change` stays.
- **Stage font:** site font (the stage text only inherited the old body font). The blockquote drops its italic.
- **Stage:**
- `.stage`: `position:relative;overflow-y:auto;scrollbar-width:none;overflow-anchor:none;container-type:size;background:#0b0b0d`, with `aria-label="An article with a tall cover"`. `overflow-anchor:none` stays (without it the shrinking cover fights the scroll).
- - The cover's full height becomes 85% of the box: `.cover{height:85cqh}` in the CSS, and `measure()` sets `FULL = Math.round(stage.clientHeight * 0.85)` (530px of a 620px stage today), so the whole cover shows on arrival: 321px at 1280×800, 276px at 1366×657, 219px at 1280×590 and 253px on phones (measured: its text, with its margins and padding, needs 171px there and 192px on phones). `--cover-full` goes; `--cover-min` stays (56px, 64px under 600px).
+ - The cover's full height becomes 85% of the box: `.cover{height:85cqh}` in the CSS, and `measure()` sets `FULL = Math.round(stage.clientHeight * 0.85)` (530px of a 620px stage today), so the whole cover shows on arrival: 321px at 1280×800, 276px at 1366×657, 219px at 1280×590 and 253px on phones (measured: its text, with its margins and padding, needs 171px there and 192px on phones). `--cover-full` goes; `--cover-min` stays (56px, 64px under 600px). The cover then moves with transforms and keeps its full height in the layout: `measure()` also sets `cover.style.height = FULL + 'px'` and `CONTENT = FULL − spacer height` (the cover's text with its margins and padding, read from `.cover-spacer`), and `render()` writes, for `v = q(lerp(FULL, MIN, e), 1)` and `d = FULL − v`: `translateY(-d)` on `.cover` and `.article-body`, `translateY(d)` on `#header-chip`, `translateY(d) scaleY(v / FULL)` on `#cover-bg` (`transform-origin:top`) and `translateY(max(0, CONTENT − v))` on `.cover-inner`. `.cover` and `.article-body` get `will-change:transform` (`auto` under reduced motion). (final review: height is no longer animated; layouts during a scroll fell from about one per two frames to none)
- The scene's `min-height:2500px` goes. Today it leaves about 1,700px of empty box after the article, so Play would spend most of its six seconds on nothing. `measure()` sets `scene.style.minHeight = Math.max(FULL + article.offsetHeight, stage.clientHeight + 440) + 'px'`, so the box scrolls far enough to finish the longest shrink and its scroll length does not change while the cover shrinks. At every measured size the first term wins, so once the cover is slim, `FULL − MIN` of box is left empty after the article: 265px at 1280×800, 163px at 1280×590, 189px on phones. `measure()` also runs after `document.fonts.ready` (the article's height depends on the font).
- A closing line fills that space (owner decision 4): `<p class="end-cue">The end · scroll back up and the cover opens again</p>`, the last child of `.scene`, with `position:absolute;left:0;right:0;bottom:0;margin:0;display:flex;align-items:center;justify-content:center` and the cue style (shared rule 14: 13px `#8a8a92`, `letter-spacing:.1em`, `text-align:center;padding:0 24px`). `measure()` sets its height to `FULL − MIN` (`.scene` is already `position:relative`).
- The cover's title becomes `<p class="cover-title" id="cover-title">` (was an `h1`, shared rule 13): the shared rule `.hb-page h1` would restyle it at 64px. `.cover-title` keeps its own look (26px, `#d1f7d6`, `line-height:1.2`, `letter-spacing:-.5px`, `margin-bottom:8px`, `transform-origin:left top`) and gets `font-weight:700`, the weight the `h1` gave it. Measured: when the cover is slim, the title's two lines scale to half size and sit 22–53px down the 56px bar (64px on phones).
- The code shown on the cover (`.cover-code`) goes, with its line in `render()` (`coverCode.style.opacity`).
- - Text on the cover: the subtitle becomes "Why a tall cover can fold into a slim bar as you read" (was "How browsers render scroll-driven animations at 60fps"); "Article · 8 min read", the title and "Matin M. · May 2026" stay. `.cover-meta`, `.author-name` and `.chip-name` become 11px (were 10px) and `.cover-sub` 14px (was 12px). `.cover-meta`, `.cover-sub` and `.author-name` use `#5fa577` (was `#3d7a52`, 3.1:1 on the cover's green; the new green is 5.3:1); `.chip-name` keeps `#d1f7d6`.
+ - Text on the cover: the subtitle becomes "Why a tall cover can fold into a slim bar as you read" (was "How browsers render scroll-driven animations at 60fps"); "Article · 8 min read", the title and "Matin M. · May 2026" stay. `.cover-meta`, `.author-name` and `.chip-name` become 11px (were 10px) and `.cover-sub` 14px (was 12px). `.cover-meta`, `.cover-sub` and `.author-name` use `#5fa577` (was `#3d7a52`, 3.1:1 on the cover's green; the new green is 5.3:1); `.chip-name` keeps `#d1f7d6`. The author chip (`#header-chip`) is `aria-hidden="true"`: it only repeats the author line on the cover.
- The article is rewritten in plain words (today's text speaks of compositors, easing curves and the removed slider), with `.article-body p` at 14px (was 12px), the headings 12px (was 11px) and the blockquote 15px (was 13px). Its three headings become `h3` (were `h2`, shared rule 13), so the `.article-body h2` rule becomes `.article-body h3`. In order:
| Part | Text |
@@ -338,13 +338,15 @@ None: leave out the `details.hb-options` block.
- [Stacking Cards](../stacking-cards/) — cards pile into a deck as you scroll
- [Scrub Animation](../scrub-animation/) — scroll plays an animation forward and back
- **README How it works:**
- - In the second snippet, `cover.style.height = lerp(530, 56, e) + 'px';` becomes `cover.style.height = lerp(FULL, 56, e) + 'px'; // FULL: 85% of the box's height`.
+ - The sentence above the second snippet, "Eight properties are then interpolated against `e`", becomes "The cover's visible height and seven other values are then worked out from `e`", and in the snippet `cover.style.height = lerp(530, 56, e) + 'px';` becomes two lines (the cover moves with transforms, final review): `const h = lerp(FULL, 56, e), d = FULL - h; // FULL: 85% of the box's height` and ``cover.style.transform = `translateY(${-d}px)`; // the cover keeps its full height and slides up``.
- In the same snippet, the comment `// also coverSub, coverCode` becomes `// also coverSub`.
- The rest is unchanged.
-- **README Production notes:** unchanged
+ - The spacer sentence ("A `flex: 1` spacer inside the cover pushes content to the bottom …") becomes: "Nothing is resized: the cover keeps its full height in the layout and slides up by what it has shrunk, and the article slides with it; the badge and the backdrop are moved back into the visible part, and once the cover is shorter than its text the text starts at the top of the bar. Back to top and Play from the end set the eased value at once." (final review)
+- **README Production notes:** the bullet "The height animation triggers layout" becomes "**Move the cover; never animate its `height`.** Writing `height` lays the page out every frame. Keep the cover at full height, slide it and the content below with `translateY()`, and squeeze the backdrop with `scaleY()` from its top edge — as the demo does." (final review). The scroll-anchoring bullet gains "This demo moves the cover with transforms, so scrolling never changes its height; the rule stays as a guard for when the box is measured again after a resize." The rest is unchanged.
- **Category line:** `01.04 · Scroll-Based`
- **Pager:** Previous: Reverse-Scrolling Columns (`../reverse-scrolling-columns/`) · Next: Fly-in Fly-out Contact List (`../fly-in-fly-out-contact-list/`)
+- **Final fix wave (Scroll-Based final review, 2026-09-30).** The cover no longer animates `height`: it keeps its full height in the layout and moves with transforms (the cover-height bullet under Stage, above), so a scroll lays the page out about twice in 150 frames at 4× CPU throttling in a phone-sized box, down from 75. `overflow-anchor:none` stays as a guard: the first Stage bullet's reason now applies when `measure()` writes the cover's height after a resize. A click on Back to top or Play sets the eased value at once, so the cover does not open again after a jump (`render(current)` runs in the same click). `#header-chip` is `aria-hidden`. `index.html` grows from 299 to 308 lines.
---
## fly-in-fly-out-contact-list — Fly-in Fly-out Contact List