Saltar al contenido
Logic2BUI

Buscar en la documentación

Busca componentes y documentación

Nuevo
Menú

Revelado al desplazar

Reproduce una receta de entrada cuando un elemento aparece en el viewport, con IntersectionObserver y el motor de movimiento sin dependencias de runtime.

Scroll down ↓

Fade up

Revealed as it scrolls into view.

Fade left

Revealed as it scrolls into view.

Scale

Revealed as it scrolls into view.

Blur

Revealed as it scrolls into view.

Instalación

npx logic2b@next add scroll-reveal

Uso

import { ScrollReveal } from "@/components/ui/scroll-reveal"

<ScrollReveal preset="fade-up">
  <Card>…</Card>
</ScrollReveal>

ScrollReveal es la variante activada por desplazamiento de Motion: en vez de reproducirse al montar, espera a que el elemento aparezca en el viewport mediante el hook useInView de IntersectionObserver y ejecuta la misma receta de entrada. Comparte todos los presets —fade, fade-up/down/left/right, scale y blur—, las propiedades duration, delay y asChild, y el fallback de prefers-reduced-motion.

El contenido permanece visible hasta que se monta y arma, por lo que buscadores y clientes sin JavaScript siempre pueden verlo. El revelado es una mejora progresiva.

Escalonar un grupo

Asigna un delay creciente a cada elemento para encadenar una lista al entrar:

{posts.map((post, i) => (
  <ScrollReveal key={post.id} preset="fade-up" delay={i * 80}>
    <PostCard {...post} />
  </ScrollReveal>
))}

Revelar en cada pasada

Por defecto, el revelado se ejecuta una vez y permanece. Usa once={false} para volver a ocultar y reproducir la receta cada vez que el elemento sale y entra en el viewport.

useInView

scroll-reveal instala el hook useInView, que también puede usarse por sí solo para condicionar cualquier contenido a la visibilidad, como un gráfico con carga diferida, un contador useCountUp o un vídeo con reproducción automática:

const [ref, inView] = useInView({ amount: 0.5 })

<section ref={ref}>{inView && <Chart />}</section>

Playground interactivo

Edita las propiedades del componente y revisa el JSX exacto antes de copiarlo. La vista previa se carga solo cuando esta sección entra en pantalla.

JSX generado
<ScrollReveal
  preset="fade-up"
  duration={500}
  delay={0}
  once
  className="rounded-lg border bg-card p-6"
>Revealed content</ScrollReveal>

Referencia de API

Generada a partir de las exportaciones públicas de TypeScript en src/ui/scroll-reveal.tsx. Las descripciones técnicas conservan el texto canónico del código fuente.

Ver JSON

ScrollRevealProps

Tipo

Plays a motion enter recipe when the element scrolls into view (rather than on mount like `<Motion>`). Built on the `useInView` IntersectionObserver hook and the motion engine's recipes, so it shares the same presets, timing and prefers-reduced-motion fallback. SSR- and no-JS-safe: it renders visible until it has mounted and armed, so search engines and scriptless clients always see the content.

interface ScrollRevealProps extends React.ComponentProps<"div">, Pick<UseInViewOptions, "once" | "amount" | "margin" | "root"> { /** Enter recipe to play when revealed. Default `"fade-up"`. */ preset?: MotionPreset /** Reveal duration in milliseconds. Overrides the 500ms default. */ duration?: number /** Reveal delay in milliseconds — the knob for staggering a group. */ delay?: number /** Merge props onto the single child instead of rendering a wrapper. */ asChild?: boolean }

ScrollReveal

Componente
Props: ScrollRevealProps
PropiedadTipoObligatoriaValor predeterminadoDescripción
presetMotionPresetNo"fade-up"Enter recipe to play when revealed. Default `"fade-up"`.
durationnumberNo—Reveal duration in milliseconds. Overrides the 500ms default.
delaynumberNo—Reveal delay in milliseconds — the knob for staggering a group.
asChildbooleanNofalseMerge props onto the single child instead of rendering a wrapper.
oncebooleanNotrueStop observing after the first time the element enters view. Default `true`.
amountnumberNo0.3Fraction of the element that must be visible to count as in view (0–1). Default `0.3`.
marginstringNo"0px"IntersectionObserver `rootMargin`, e.g. `"-10% 0px"`. Default `"0px"`.

Contrato de accesibilidad

Comportamiento legible por máquinas y responsabilidades de quien integra scroll-reveal. Los detalles normativos conservan el texto canónico del registro.

Ver JSON
Soporte
Contrato de composición
Patrón
scroll-triggered reveal
Intersection Observer + Motion

Semántica incorporada

  • Content remains in the document reading order and preserves the rendered child semantics.

Responsabilidades de integración

  • Render meaningful content without requiring scroll activation and disable movement for reduced-motion preferences.

Limitaciones conocidas

  • • Incorrect initial styles can hide content when scripting or observation is unavailable.