Cómo funciona
Two layers: a still outer placeholder that IntersectionObserver watches, and an inner layer that animates only opacity, transform and a soft blur (6px by default, set --ds-scroll-reveal-blur to 0px for a crisp entrance). Observing the still layer avoids flicker, because an offset would change the element's own visibility. Instances with the same root and options share one observer, so items entering together are staggered by page position while later ones appear at once. It never listens to scroll.
Úsalo para
- Long pages revealed section by section: selling points, process steps, highlights.
- Cards, course lists and review walls that scroll down, where the first few items should appear in rhythm.
- Campaign and landing pages that need a little pacing to guide the eye.
Busca otra opción cuando
- Key content on the first screen, such as the headline, price or main button: people should not wait, and it stays transparent when rendered on the server before JavaScript runs.
- Tool-like pages such as admin tables, forms and order details: content must be readable at once.
- Virtualized lists with hundreds of items: nodes are created and destroyed repeatedly and would reveal every time.
- A headline that should appear word by word: use a text reveal.
Uso
import { useRef } from 'react'
import { ScrollReveal } from './ScrollReveal.jsx'
// Whole-page scrolling: no root needed
export function Features() {
return (
<>
<ScrollReveal as="section">
<h2>Free returns</h2>
</ScrollReveal>
<ScrollReveal variant="scale" delay={120}>
<img src="/returns.png" alt="How returns work" />
</ScrollReveal>
</>
)
}
// Scrolling inside a container: pass the container's ref as root
export function PopularStays({ list }) {
const scrollRef = useRef(null)
return (
<div ref={scrollRef} style={{ height: 360, overflowY: 'auto', overflowX: 'hidden' }}>
<ul>
{list.map((stay) => (
<ScrollReveal key={stay.id} as="li" root={scrollRef}>
<StayCard stay={stay} />
</ScrollReveal>
))}
</ul>
</div>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
variant | 'fade-up' | 'fade' | 'scale' | 'slide-left' | 'slide-right' | 'fade-up' | How it appears: rise and fade, fade only, scale up from 0.92, slide in from the right, slide in from the left. |
delay | number | 0 | Extra wait in ms after entering the viewport. |
stagger | number | 60 | Gap in ms between elements entering together, ordered by page position, up to 6. Items entering alone are unaffected; 0 turns it off. |
duration | number | 560 | Reveal time in ms. When omitted, follows --ds-duration-slower. |
distance | number | 24 | Offset in px, used by fade-up, slide-left and slide-right. |
once | boolean | true | Plays once. When false, it resets after fully leaving the viewport and replays on re-entry. |
threshold | number | 0.2 | Fraction that must be visible to count as entered, 0 to 1. Elements larger than the viewport count as soon as they peek in. |
root | RefObject | Element | null | browser viewport | Scroll container (element or its ref). Required when content scrolls inside an overflow: auto container. |
rootMargin | string | '0px' | Grows or shrinks the detection area, CSS margin syntax, such as '0px 0px -10% 0px'. |
onReveal | () => void | — | Called when it starts to appear (every re-entry when once is false). Handy for impression tracking. |
as | 'div' | 'section' | 'article' | 'li' | 'header' | 'footer' | 'aside' | 'figure' | 'div' | Root tag. Use 'li' inside a <ul>. |
...rest | HTMLAttributes<HTMLElement> | — | Other attributes, such as className, style and id, go to the root (the still placeholder). |
Accesibilidad
- Before entering it is only opacity: 0, never visibility: hidden or display: none, so content stays in the accessibility tree and screen readers still read it.
- Tabbing into content that has not appeared yet shows it at once (:focus-within), so focus never lands on something invisible.
- With reduced motion, content is visible with no offset, blur or transition; onReveal still fires on real entry.
- Where IntersectionObserver is missing, or rootMargin is invalid, content is shown directly.
- Semantic tags are kept: as can be section, article, li and so on, with no meaningless extra levels.
Movimiento
Reveal: opacity 0 to 1, a 6px blur clearing, plus a 24px offset (or scale 0.92 to 1) over 560ms with the reveal curve cubic-bezier(0.22, 1, 0.36, 1). Items entering together are staggered by 60ms, up to 6. The reset after leaving has no transition.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
ScrollReveal.jsxscroll-reveal.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.



