滚动入场
Scroll Reveal
元素滚进可视区域时,从轻微位移和透明状态过渡到原位。
适用场景
在读者浏览到功能卡片、内容插图或短区块时引导注意力。 进入动效用一次短过渡就够了。元素出现后保持可见,读者回头查找时能直接看到内容。
应用示例
博物馆展览导览里,第一件展品的照片进入视口时,轻轻上移并淡入。访客往回滚动读图注时,照片仍留在原位。
也叫
- 滚动显现
AI 提示词
给【目标区块】加上 Scroll Reveal。元素进入实际滚动容器的可视范围后,用约 360 毫秒从淡出、下移 12 像素过渡到完全可见的原位。保持区块占位,每次访问只播一次。内容默认可见,减少动态效果或脚本不可用时直接显示最终状态。
示例代码
保存为 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-scene {
display: grid;
gap: 5px;
width: min(100%, 338px);
}
.scroll-hint {
color: #e2d8f4;
font-size: 10px;
font-weight: 650;
text-align: center;
}
.demo-scroller {
--viewport-height: clamp(86px, 57vh, 210px);
display: block;
height: var(--viewport-height);
overflow: auto;
overscroll-behavior: contain;
scrollbar-width: thin;
scrollbar-color: #8c76bb #29213d;
background: #221b35;
border: 1px solid #846dac;
border-radius: 9px;
}
.reveal-scroll { padding: 8px; }
.reveal-row {
display: grid;
min-height: 62px;
height: calc(var(--viewport-height) * 0.7);
margin-bottom: 8px;
}
.reveal-row:last-child { margin-bottom: 0; }
.reveal-card {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 10px;
color: #241935;
background: #dbceff;
border-radius: 7px;
}
.reveal-row:nth-child(2) .reveal-card { background: #ffd7c1; }
.reveal-row:nth-child(3) .reveal-card { background: #c4f3d8; }
.reveal-card i { font: 650 10px ui-monospace, monospace; }
.reveal-card strong { font-size: 12px; }
.reveal-scroll[data-ready] .reveal-row:not([data-shown]) .reveal-card {
opacity: 0;
transform: translateY(15px);
}
.reveal-scroll[data-ready] .reveal-card {
transition: opacity 350ms ease, transform 350ms ease;
}
@media (prefers-reduced-motion: reduce) {
.reveal-scroll .reveal-row .reveal-card {
opacity: 1 !important;
transform: none !important;
transition: none;
}
}
</style>
</head>
<body>
<main class="demo">
<section class="scroll-scene">
<span id="reveal-hint" class="scroll-hint">在框内向下滚动 ↓</span>
<div class="demo-scroller reveal-scroll" role="region" tabindex="0" aria-labelledby="reveal-hint">
<article class="reveal-row">
<span class="reveal-card"><i aria-hidden="true">01</i><strong>工作台</strong></span>
</article>
<article class="reveal-row">
<span class="reveal-card"><i aria-hidden="true">02</i><strong>材料样本</strong></span>
</article>
<article class="reveal-row">
<span class="reveal-card"><i aria-hidden="true">03</i><strong>最终构图</strong></span>
</article>
</div>
</section>
</main>
<script>
const scroller = document.querySelector(".reveal-scroll");
if ("IntersectionObserver" in window) {
const entries = scroller.querySelectorAll(".reveal-row");
entries[0].setAttribute("data-shown", "");
scroller.setAttribute("data-ready", "");
const observer = new IntersectionObserver((visible) => {
for (const entry of visible) {
if (!entry.isIntersecting) continue;
entry.target.setAttribute("data-shown", "");
observer.unobserve(entry.target);
}
}, { root: scroller, threshold: 0.3 });
entries.forEach((entry) => observer.observe(entry));
}
</script>
</body>
</html>UI Skills 原创示例