滚动遮罩揭示
Scroll Mask Reveal
裁切边缘随滚动移开,逐步露出更多图像。
适用场景
适合在叙事中从一侧揭示装饰图片。 根据画面内容选择好裁切方向。图注和可访问说明可以始终保留,方便用户理解正在揭开的内容。
应用示例
剧院的新演出季介绍页里,观众向下滚动时,像幕布一样的遮罩向上退开。下面的舞台布景图从边缘逐渐显露。
AI 提示词
为【目标位置】添加 Scroll Mask Reveal(滚动遮罩揭示)。用归一化滚动进度驱动 clip-path: inset()。把控件放在被裁切区域之外,在减少动态效果模式下完整显示。在减少动态效果模式下保持内容可读,并保留键盘操作。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>滚动遮罩揭示</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-panel {
position: relative;
width: min(100%, 215px);
height: 133px;
overflow: auto;
overscroll-behavior: contain;
scrollbar-width: thin;
scrollbar-color: #9881cb #2e2540;
border: 1px solid #806ca8;
border-radius: 9px;
background: #2d2342;
color: #f5efff;
font: 650 12px system-ui, sans-serif;
}
.scroll-panel p { margin: 0; }
.scroll-panel hr { border: 0; margin: 6px 0; height: 5px; border-radius: 9px; background: #ae96dc4a; }
.scroll-panel hr:nth-of-type(2n) { width: 72%; }
.scroll-note { color: #ddcff1; text-align: center; font-size: 10px; }
.scroll-panel:focus-visible { outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
.scroll-panel, .scroll-panel *, .scroll-panel *::before, .scroll-panel *::after {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
.scroll-track {
position: relative;
min-height: 335px;
background: repeating-linear-gradient(0deg, #9c7fac26 0 1px, transparent 1px 23px);
}
.scroll-pin {
position: sticky; top: 0; height: 124px;
display: grid; align-content: center; justify-items: center; gap: 5px;
padding: 8px;
}
.motion-art {
position: relative; width: 92px; height: 58px;
border: 1px solid #dfc6f6b0; border-radius: 11px;
background: radial-gradient(circle at 70% 30%,#fbe0a6 0 9px,transparent 10px),
linear-gradient(145deg,#b98cb2 30%,#8d6abc 65%,#49346e);
box-shadow: 0 5px 8px #1c142b70;
}
.motion-art::after {
content: ''; position: absolute; inset: 40% 0 0; border-radius: 0 0 10px 10px;
background: #443469; clip-path: polygon(0% 40%,32% 0%,63% 62%,81% 20%,100% 56%,100% 100%,0 100%);
}
.motion-art { clip-path: inset(0 calc((1 - var(--progress,0)) * 88%) 0 0 round 10px); }
</style>
</head>
<body>
<main class="demo">
<div class="scroll-panel" role="region" tabindex="0" aria-label="滚动遮罩演示">
<div class="scroll-track"><div class="scroll-pin"><div class="motion-art" aria-hidden="true"></div><p class="scroll-note">向下滚动 ↓</p></div></div>
</div>
</main>
<script>
const panel = document.querySelector('.scroll-panel');
const reduce = matchMedia('(prefers-reduced-motion: reduce)');
let scheduled = false;
function update() {
const total = panel.scrollHeight - panel.clientHeight;
const progress = total > 0 ? Math.max(0, Math.min(1, panel.scrollTop / total)) : 0;
panel.style.setProperty('--progress', String(reduce.matches ? 1 : progress));
scheduled = false;
}
function schedule() {
if (scheduled) return;
scheduled = true;
requestAnimationFrame(update);
}
panel.addEventListener('scroll', schedule, { passive: true });
reduce.addEventListener('change', schedule);
update();
</script>
</body>
</html>UI Skills 原创示例