Scroll Shape Morph
滚动多边形轮廓变形
The same eight-sided clipping window changes its contour as you scroll.
Where to use it
Move a product image between carefully designed cutout shapes. Choose compatible outlines and leave space around the subject at every intermediate shape. Small cutouts near important details are easy to miss.
Practical example
In a luggage lookbook, a suitcase photo starts in a compact octagonal window that widens into a flattened frame as the reader scrolls. The handle and wheels remain visible while the opening changes.
AI prompt
Add Scroll Shape Morph to [target]. Choose two clip-path polygons with matching vertex counts and winding order. Interpolate each vertex using scroll progress and keep the underlying artwork anchored. Keep the controls keyboard accessible and provide a reduced-motion state.
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 Shape Morph</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;
}
.scroll-port {
--frame: clamp(112px, 75vh, 242px);
--p: 0;
width: min(100%, 290px); height: var(--frame);
overflow-y:auto; overflow-x:hidden; scroll-behavior:auto;
overscroll-behavior:contain; scrollbar-width:thin;
scrollbar-color:#a79bd5 #20223d; border-radius:12px;
border:1px solid #a79bd567; background:#20233c; color:#f5f2ff;
}
.scroll-port:focus-visible { outline-offset: 3px; }
.scroll-track { position:relative; min-height:calc(var(--frame) + 235px); }
.scroll-pin { position:sticky; top:0; height:var(--frame); overflow:hidden; }
.scroll-pin .tag { position:absolute; z-index:4; left:8px; bottom:9px; font-size:10px; color:#ecfcff; padding:4px 6px; background:#17152ce8; border-radius:4px; }
.scroll-panel { min-height:62px; padding:9px; border:1px solid #adb2e345; border-radius:8px; background:linear-gradient(120deg,#314861,#3e346a); }
.scene-art {
position: absolute; inset: 0;
background:
radial-gradient(circle at 68% 33%, var(--sun, #ffdbac) 0 11%, transparent 11.8%),
linear-gradient(26deg, var(--land, #435b77) 0 28%, transparent 28.6%),
linear-gradient(-33deg, var(--ridge, #736ca9) 0 32%, transparent 32.5%),
linear-gradient(145deg, var(--horizon, #151b48), var(--sky, #7c729a));
}
.scene-art::after {
position: absolute; inset: 0; content: '';
background-image: repeating-linear-gradient(0deg, #fff0 0 10px, #ccceff20 11px, #fff0 12px);
mask-image: linear-gradient(transparent 45%, black 100%);
}
.morph-shot { inset:8px; clip-path:var(--mask,polygon(9% 0%,91% 0%,100% 9%,100% 91%,91% 100%,9% 100%,0% 91%,0% 9%)); }
.scroll-pin:has(.morph-shot) { background:radial-gradient(circle at 13% 18%,#9bd7fa45 1px,transparent 2px) 0 0 / 15px 15px, #151c37; }
@media (prefers-reduced-motion: reduce) {
.lab, .lab *, .lab::before, .lab::after, .lab *::before, .lab *::after {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<main class="demo">
<div class="lab scroll-port" role="region" tabindex="0" aria-label="Scroll to reshape the window"><div class="scroll-track"><div class="scroll-pin"><div class="scene-art morph-shot" aria-hidden="true"></div><span class="tag" aria-hidden="true">Octagonal window</span></div></div></div>
</main>
<script>
const port = document.querySelector('.scroll-port');
const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const listeners = [];
let scheduled = 0;
function sample() {
const max = Math.max(1,port.scrollHeight - port.clientHeight);
return Math.max(0,Math.min(1,port.scrollTop / max));
}
function update() {
scheduled = 0;
const progress = sample();
port.style.setProperty('--p', progress.toFixed(4));
for (const callback of listeners) callback(progress);
}
function schedule() { if (!scheduled) scheduled = requestAnimationFrame(update); }
function onScroll(callback) { listeners.push(callback); callback(sample()); }
port.addEventListener('scroll', schedule, {passive:true});
new ResizeObserver(schedule).observe(port);
reduced.addEventListener('change', schedule);
update();
const initial = [[9,0],[91,0],[100,9],[100,91],[91,100],[9,100],[0,91],[0,9]];
const final = [[43,10],[59,10],[88,39],[88,62],[64,90],[38,90],[13,63],[13,37]];
onScroll((progress) => {
const weight = reduced.matches ? 0 : progress;
const vertices = initial.map(([x,y], i) => (x + (final[i][0]-x)*weight).toFixed(2) + '% ' + (y + (final[i][1]-y)*weight).toFixed(2) + '%');
port.style.setProperty('--mask', 'polygon(' + vertices.join(',') + ')');
});
</script>
</body>
</html>Original example by UI Skills