Scroll-Scrubbed Frame Sequence
滚动逐帧播放
Each scroll position selects a discrete frame. Scrolling forward separates the lens assembly and reversing reassembles it.
Where to use it
Explain how a product is assembled or let readers move through an illustrated process at their own pace. Plan frames around changes readers need to inspect and include useful intermediate positions for reverse scrolling.
Practical example
On a mechanical watch's product page, scrolling separates the movement into the mainspring, gear train, and escapement. Visitors can reverse a short distance to see how two parts fit together.
AI prompt
Add a Scroll-Scrubbed Frame Sequence to [target section]. Keep the display sticky while its track scrolls. Clamp normalized scroll progress, round it to a frame index, and render only when that index changes. Enable reverse playback with the same mapping, expose the frame count, and provide a complete static frame for 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>Scroll-Scrubbed Frame Sequence</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;
}
.sequence-scroll {
--viewport: clamp(126px, calc(100vh - 33px), 200px);
width: min(100%, 430px);
height: var(--viewport);
overflow: hidden auto;
overscroll-behavior: contain;
scrollbar-width: thin;
scrollbar-color: #9ea9ee #282745;
border: 1px solid #b3b2ff55;
border-radius: 10px;
background: #10233a;
}
.sequence-track { height: 530px; }
.sequence-stage {
position: sticky; top: 0; height: calc(var(--viewport) - 2px);
display: grid; grid-template-rows: minmax(0, 1fr) 27px;
}
.sequence-stage canvas { display: block; width: 100%; height: 100%; object-fit: contain; }
.sequence-status {
display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center; gap: 7px; padding: 0 8px;
color: #dce6ff; background: #172442; border-top: 1px solid #aabaff30;
font: 620 10px/1.2 system-ui, sans-serif;
}
.sequence-status progress { width: 100%; height: 7px; accent-color: #98efd9; }
.frame-index { white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) {
.sequence-scroll { overflow: hidden; }
.sequence-track { height: calc(var(--viewport) - 2px); }
.sequence-status { grid-template-columns: 1fr; }
.sequence-status progress, .frame-index { display: none; }
}
</style>
</head>
<body>
<main class="demo">
<div class="sequence-scroll" role="region" tabindex="0" aria-label="Lens assembly scroll preview">
<div class="sequence-track">
<div class="sequence-stage">
<canvas width="432" height="162" role="img" aria-label="Illustrated lens assembly"></canvas>
<div class="sequence-status">
<span>Lens assembly</span>
<progress value="1" max="24" aria-label="Current frame"></progress>
<span class="frame-index" aria-hidden="true">01 / 24</span>
</div>
</div>
</div>
</div>
</main>
<script>
const scrollport = document.querySelector('.sequence-scroll');
const canvas = scrollport.querySelector('canvas');
const context = canvas.getContext('2d');
const indicator = scrollport.querySelector('progress');
const frameIndex = scrollport.querySelector('.frame-index');
const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');
const frameCount = indicator.max;
const parts = [
{ position: 166, offset: -81, radius: 35, depth: 16, tone: '#9eebdf' },
{ position: 187, offset: -43, radius: 28, depth: 11, tone: '#a9cbff' },
{ position: 198, offset: -5, radius: 23, depth: 8, tone: '#ffbdca' },
{ position: 211, offset: 32, radius: 29, depth: 10, tone: '#aabaff' },
{ position: 226, offset: 58, radius: 36, depth: 35, tone: '#8498e8' },
];
let previousFrame = -1;
let animation = 0;
function drawEllipse(x, y, horizontal, vertical, fill) {
context.beginPath();
context.ellipse(x, y, horizontal, vertical, 0, 0, Math.PI * 2);
context.fillStyle = fill;
context.fill();
}
function drawPart(part, travel) {
const x = part.position + part.offset * travel;
const y = 81;
const halfWidth = part.radius / 3;
const shading = context.createLinearGradient(0, y - part.radius, 0, y + part.radius);
shading.addColorStop(0, part.tone);
shading.addColorStop(.47, '#394b75');
shading.addColorStop(1, '#121c34');
drawEllipse(x + part.depth, y, halfWidth, part.radius, '#222f50');
context.fillStyle = shading;
context.fillRect(x, y - part.radius, part.depth, part.radius * 2);
drawEllipse(x, y, halfWidth, part.radius, part.tone);
drawEllipse(x - 1, y, halfWidth * .73, part.radius - 5, '#1b2448');
drawEllipse(x - 2, y, halfWidth * .53, part.radius - 10, '#455486');
drawEllipse(x - 3, y - part.radius * .21, 2.5, 10, '#d6fff2');
}
function drawFrame(index) {
const { width, height } = canvas;
const normalized = index / (frameCount - 1);
const travel = normalized * normalized * (3 - 2 * normalized);
const background = context.createRadialGradient(214, 80, 5, 214, 80, 230);
background.addColorStop(0, '#2d435e');
background.addColorStop(1, '#10233a');
context.fillStyle = background;
context.fillRect(0, 0, width, height);
context.beginPath();
for (let x = 24; x < width; x += 24) { context.moveTo(x, 12); context.lineTo(x, height - 12); }
for (let y = 24; y < height; y += 24) { context.moveTo(12, y); context.lineTo(width - 12, y); }
context.strokeStyle = '#b3d9ff19';
context.stroke();
context.beginPath();
context.setLineDash([4, 5]);
context.moveTo(43, 81);
context.lineTo(385, 81);
context.strokeStyle = '#b5efeb80';
context.stroke();
context.setLineDash([]);
for (let index = parts.length - 1; index >= 0; index -= 1) drawPart(parts[index], travel);
}
function updateFrame() {
animation = 0;
const scrollable = scrollport.scrollHeight - scrollport.clientHeight;
const progress = scrollable ? Math.min(1, Math.max(0, scrollport.scrollTop / scrollable)) : 0;
const index = reducedMotion.matches ? frameCount - 1 : Math.round(progress * (frameCount - 1));
if (index === previousFrame) return;
previousFrame = index;
drawFrame(index);
indicator.value = index + 1;
frameIndex.textContent = String(index + 1).padStart(2, '0') + ' / ' + frameCount;
}
function scheduleUpdate() {
if (!animation) animation = requestAnimationFrame(updateFrame);
}
scrollport.addEventListener('scroll', scheduleUpdate, { passive: true });
reducedMotion.addEventListener('change', () => {
scrollport.tabIndex = reducedMotion.matches ? -1 : 0;
scheduleUpdate();
});
new ResizeObserver(scheduleUpdate).observe(scrollport);
scrollport.tabIndex = reducedMotion.matches ? -1 : 0;
updateFrame();
</script>
</body>
</html>Original example by UI Skills