Scroll Reveal
Blocks fade and rise into view as they enter a scrolling area, once.
AI prompt
Build a 300x200px scroll container (overflow auto, hidden scrollbar optional) containing six content blocks of 80px height each, with a small title and two grey text lines. Hide each block initially with opacity 0 and translateY(18px) using a js-enabled class on the container, so content stays visible if JavaScript fails. Use an IntersectionObserver with the container as root, threshold 0.15 and a rootMargin of 0px 0px -10% 0px: when a block intersects, add a revealed class that transitions opacity and transform over 500ms cubic-bezier(.2,.7,.2,1) with a transition-delay of 70ms times its order among blocks revealed in the same callback, then unobserve it. Because an IntersectionObserver does not fire for blocks that were skipped by a fast scroll, also listen to the container's scroll event (passive, throttled with requestAnimationFrame) and reveal any unrevealed block whose bottom edge is above the container's top edge, without a delay. Under prefers-reduced-motion add the revealed class to all blocks immediately and never hide them. Include a text hint "Scroll inside the box".About this pattern
Definition
Content starts slightly lowered and transparent, and animates to its place the first time it scrolls into view. An IntersectionObserver detects visibility without scroll listeners.
Purpose & UX principles
- Gives long pages a sense of progression and draws attention to what is arriving.
- Runs once per element, so scrolling back up never re-hides content.
- Content is fully visible without JavaScript and for reduced-motion users; the effect is a progressive enhancement.
Interaction states
- Hidden (before), revealed (after), kept revealed on scroll back.
Motion specification
- Opacity 0 to 1 and translateY 18px to 0, 500ms cubic-bezier(.2,.7,.2,1), with a 70ms stagger for elements entering together.
- Reduced motion: everything is visible immediately.
Responsive behaviour
- Uses a rootMargin so elements start revealing just before they are fully in view.
- The same code works for the page or any scroll container.
Code
<div class="sc js" id="sc">
<article class="bk"><b>Discover</b><i></i><i></i></article><article class="bk"><b>Explore</b><i></i><i></i></article><article class="bk"><b>Understand</b><i></i><i></i></article>
<article class="bk"><b>Experiment</b><i></i><i></i></article><article class="bk"><b>Create</b><i></i><i></i></article><article class="bk"><b>Share</b><i></i><i></i></article>
</div>
<p class="hint">Scroll inside the box</p>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.sc{width:min(300px,100%);height:200px;overflow:auto;padding:10px;background:var(--surface);border:1px solid var(--line);border-radius:14px;scrollbar-width:thin}
.bk{height:80px;margin-bottom:10px;padding:14px;border:1px solid var(--line);border-radius:12px;background:var(--bg)}
.bk b{display:block;font-size:14px;font-weight:600;margin-bottom:8px}
.bk i{display:block;height:7px;border-radius:4px;background:#dcdcd7;margin-bottom:6px;width:90%}
.bk i+i{width:60%}
.js .bk{opacity:0;transform:translateY(18px)}
.js .bk.revealed{opacity:1;transform:none;transition:opacity .5s cubic-bezier(.2,.7,.2,1),transform .5s cubic-bezier(.2,.7,.2,1)}
.hint{text-align:center;font-size:11.5px;color:var(--muted);margin-top:8px}
@media (prefers-reduced-motion:reduce){.js .bk{opacity:1;transform:none}}const sc=document.getElementById('sc'),bks=[...sc.querySelectorAll('.bk')];
if(matchMedia('(prefers-reduced-motion: reduce)').matches||!('IntersectionObserver' in window)){bks.forEach(b=>b.classList.add('revealed'));}
else{const io=new IntersectionObserver(es=>{let n=0;es.forEach(en=>{if(!en.isIntersecting)return;const b=en.target;b.style.transitionDelay=(n++*70)+'ms';b.classList.add('revealed');io.unobserve(b);});},{root:sc,threshold:.15,rootMargin:'0px 0px -10% 0px'});bks.forEach(b=>io.observe(b));
let q=0;sc.addEventListener('scroll',()=>{if(q)return;q=requestAnimationFrame(()=>{q=0;const top=sc.getBoundingClientRect().top;bks.forEach(b=>{if(!b.classList.contains('revealed')&&b.getBoundingClientRect().bottom<top){b.style.transitionDelay='0ms';b.classList.add('revealed');io.unobserve(b);}});});},{passive:true});}One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Scroll Reveal — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.sc{width:min(300px,100%);height:200px;overflow:auto;padding:10px;background:var(--surface);border:1px solid var(--line);border-radius:14px;scrollbar-width:thin}
.bk{height:80px;margin-bottom:10px;padding:14px;border:1px solid var(--line);border-radius:12px;background:var(--bg)}
.bk b{display:block;font-size:14px;font-weight:600;margin-bottom:8px}
.bk i{display:block;height:7px;border-radius:4px;background:#dcdcd7;margin-bottom:6px;width:90%}
.bk i+i{width:60%}
.js .bk{opacity:0;transform:translateY(18px)}
.js .bk.revealed{opacity:1;transform:none;transition:opacity .5s cubic-bezier(.2,.7,.2,1),transform .5s cubic-bezier(.2,.7,.2,1)}
.hint{text-align:center;font-size:11.5px;color:var(--muted);margin-top:8px}
@media (prefers-reduced-motion:reduce){.js .bk{opacity:1;transform:none}}
</style></head>
<body><div class="stage">
<div class="sc js" id="sc">
<article class="bk"><b>Discover</b><i></i><i></i></article><article class="bk"><b>Explore</b><i></i><i></i></article><article class="bk"><b>Understand</b><i></i><i></i></article>
<article class="bk"><b>Experiment</b><i></i><i></i></article><article class="bk"><b>Create</b><i></i><i></i></article><article class="bk"><b>Share</b><i></i><i></i></article>
</div>
<p class="hint">Scroll inside the box</p>
</div>
<script>
const sc=document.getElementById('sc'),bks=[...sc.querySelectorAll('.bk')];
if(matchMedia('(prefers-reduced-motion: reduce)').matches||!('IntersectionObserver' in window)){bks.forEach(b=>b.classList.add('revealed'));}
else{const io=new IntersectionObserver(es=>{let n=0;es.forEach(en=>{if(!en.isIntersecting)return;const b=en.target;b.style.transitionDelay=(n++*70)+'ms';b.classList.add('revealed');io.unobserve(b);});},{root:sc,threshold:.15,rootMargin:'0px 0px -10% 0px'});bks.forEach(b=>io.observe(b));
let q=0;sc.addEventListener('scroll',()=>{if(q)return;q=requestAnimationFrame(()=>{q=0;const top=sc.getBoundingClientRect().top;bks.forEach(b=>{if(!b.classList.contains('revealed')&&b.getBoundingClientRect().bottom<top){b.style.transitionDelay='0ms';b.classList.add('revealed');io.unobserve(b);}});});},{passive:true});}
</script>
</body></html>