Scroll Reveal
滚动入场
An element fades and slides into place when it enters the visible area.
Where to use it
Introduce feature cards, editorial images, or short sections as the reader reaches them. Give each section a single short entrance and keep the content visible once it arrives. This lets readers scroll back and find it immediately.
Practical example
In a museum's exhibition guide, the first artifact photograph fades in and rises slightly as it enters the viewport. It stays in place when the visitor scrolls back to reread its caption.
Also called
- Scroll-Triggered Reveal
AI prompt
Add Scroll Reveal to [target sections]. When each section enters its actual scroll container, animate its opacity and about 12px of upward travel over 360ms. Reserve the element’s layout space and play once per visit. Start with visible content and show the final state with reduced motion or without JavaScript.
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 Reveal</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">Scroll inside ↓</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>Work table</strong></span>
</article>
<article class="reveal-row">
<span class="reveal-card"><i aria-hidden="true">02</i><strong>Material study</strong></span>
</article>
<article class="reveal-row">
<span class="reveal-card"><i aria-hidden="true">03</i><strong>Final composition</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>Original example by UI Skills