Pinned Scroll Chapters
滚动分镜
A scene stays in view as the accompanying text scrolls. A new composition appears when the next chapter crosses the middle of the viewport.
Where to use it
Walk readers through an editorial feature, product teardown, or illustrated process. Choose one visual for each chapter and align the scene change with the paragraph that describes it. Keep the pinned area short enough to fit with the text.
Practical example
In a feature about recycling bottles, a diagram stays visible while the sections for sorting, rinsing, and melting pass beside it. The scene updates to the corresponding facility at each chapter.
AI prompt
Add pinned scrollytelling to [target section]. Pair a sticky visual column with semantic chapters in normal document flow. When a chapter crosses the midpoint of the scroll region, update the highlighted chapter and crossfade to its illustration. Keep scroll and keyboard navigation native. Switch the illustrations immediately with reduced motion.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pinned Scroll Chapters</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.chapter-view {
--scene-height: clamp(144px, 57vh, 255px);
display: grid;
grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
align-items: start;
position: relative;
overflow: auto;
overscroll-behavior: contain;
scrollbar-width: thin;
scrollbar-color: #629399 #153033;
width: min(100%, 490px);
height: var(--scene-height);
border-radius: 14px;
background: #11242a;
box-shadow: 0 0 0 1px #638a8d80;
}
.chapter-stage {
position: sticky;
top: 0;
height: var(--scene-height);
overflow: hidden;
background: #10383d;
}
.scene { position: absolute; inset: 0; overflow: hidden; opacity: 0; transition: opacity 320ms ease; }
.chapter-stage[data-active-chapter="0"] .surface,
.chapter-stage[data-active-chapter="1"] .twilight,
.chapter-stage[data-active-chapter="2"] .midnight { opacity: 1; }
.scene i, .scene b { position: absolute; display: block; }
.surface { background: linear-gradient(167deg, #8affdd 0%, #39afad 32%, #10515b 80%); }
.surface i { top: 12%; left: 15%; width: 43%; aspect-ratio: 1; border-radius: 50%; background: #fff7b6; box-shadow: 0 0 30px #f8ffd5b0; }
.surface b { inset: auto -8% 0; height: 42%; background: linear-gradient(145deg, #168c86, #0b373e); clip-path: polygon(0 55%, 15% 28%, 29% 33%, 46% 11%, 67% 30%, 80% 12%, 100% 5%, 100% 100%, 0% 100%); }
.twilight { background: radial-gradient(ellipse at 70% 0%, #47739a, #173e5b 55%, #152737 89%); }
.twilight i { top: 26%; left: 45%; width: 39%; height: 27%; transform: rotate(-13deg); border: 2px solid #95e8ff; border-radius: 53% 64% 45% 46%; background: linear-gradient(#6dbfd4a8, #8ccbf529); box-shadow: 0 0 17px #7df4ff67; }
.twilight b { top: 49%; left: 53%; width: 25%; height: 29%; border-radius: 0 0 40% 40%; background: repeating-linear-gradient(82deg, transparent 0 5px, #b7e9ff85 5px 6px, transparent 6px 11px); transform: skewX(-11deg); }
.midnight { background: radial-gradient(ellipse at 45% 49%, #303055, #151936 55%, #121928 88%); }
.midnight i { top: 27%; left: 15%; width: 72%; height: 43%; transform: rotate(-13deg); border-radius: 65% 21% 58% 42%; background: radial-gradient(circle at 77% 31%, #f9ffc4 0 4%, transparent 6%), linear-gradient(160deg, #8f80f1, #4d3bae 44%, #313284 80%); box-shadow: 0 0 18px #7a7eed8f; }
.midnight b { top: 22%; left: 65%; width: 10%; aspect-ratio: 1; border-radius: 50%; background: #fff2ae; box-shadow: 0 0 14px 6px #d9fdeb70; }
.scene-index { position: absolute; bottom: 7px; left: 8px; padding: 3px 6px; border-radius: 4px; background: #111e31df; color: white; font-size: 11px; font-variant-numeric: tabular-nums; }
.chapter { display: grid; align-content: center; gap: 5px; min-height: var(--scene-height); padding: 10px; border-inline-start: 2px solid transparent; background: #11242a; transition: border-color 320ms ease; }
.chapter[aria-current] { border-inline-start-color: #81f0c8; }
.chapter h2 { margin: 0; color: #e8f8f0; font-size: clamp(12px, 3vw, 18px); line-height: 1.15; }
.chapter p { margin: 0; color: #bad8d6; font-size: clamp(10px, 2.4vw, 14px); line-height: 1.35; }
@media (prefers-reduced-motion: reduce) {
.scene, .chapter { transition: none; }
}
</style>
</head>
<body>
<main class="demo">
<div class="chapter-view" role="region" tabindex="0" data-testid="effect-demo-chapter-scroll" aria-label="Scroll through the ocean layers">
<div class="chapter-stage" aria-hidden="true" data-active-chapter="0">
<div class="scene surface"><i></i><b></b></div>
<div class="scene twilight"><i></i><b></b></div>
<div class="scene midnight"><i></i><b></b></div>
<span class="scene-index">1 / 3</span>
</div>
<div class="chapter-list">
<section class="chapter" aria-current="step">
<h2>Sunlit water</h2>
<p>Light reaches the reef and its bright shoals.</p>
</section>
<section class="chapter">
<h2>Twilight zone</h2>
<p>Blue light fades as the water grows colder.</p>
</section>
<section class="chapter">
<h2>Midnight zone</h2>
<p>A few creatures make light of their own.</p>
</section>
</div>
</div>
</main>
<script>
const scrollView = document.querySelector('.chapter-view');
const stage = document.querySelector('.chapter-stage');
const counter = stage.querySelector('.scene-index');
const chapters = Array.from(document.querySelectorAll('.chapter'));
let active = 0;
let scheduled = false;
function updateChapter() {
scheduled = false;
const midpoint = scrollView.scrollTop + scrollView.clientHeight / 2;
let next = active;
for (let index = 0; index < chapters.length; index++) {
if (chapters[index].offsetTop > midpoint) break;
next = index;
}
if (next === active) return;
chapters[active].removeAttribute('aria-current');
chapters[next].setAttribute('aria-current', 'step');
stage.dataset.activeChapter = String(next);
counter.textContent = (next + 1) + ' / ' + chapters.length;
active = next;
}
function queueUpdate() {
if (scheduled) return;
scheduled = true;
requestAnimationFrame(updateChapter);
}
scrollView.addEventListener('scroll', queueUpdate, { passive: true });
addEventListener('resize', queueUpdate);
queueUpdate();
</script>
</body>
</html>Original example by UI Skills