本文へ移動
日本語

仕組み

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.

向いている場面

  • 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.

向かない場面

  • 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.

使い方

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>
  )
}

プロパティ

プロパティ型既定値説明
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.
delaynumber0Extra wait in ms after entering the viewport.
staggernumber60Gap in ms between elements entering together, ordered by page position, up to 6. Items entering alone are unaffected; 0 turns it off.
durationnumber560Reveal time in ms. When omitted, follows --ds-duration-slower.
distancenumber24Offset in px, used by fade-up, slide-left and slide-right.
oncebooleantruePlays once. When false, it resets after fully leaving the viewport and replays on re-entry.
thresholdnumber0.2Fraction that must be visible to count as entered, 0 to 1. Elements larger than the viewport count as soon as they peek in.
rootRefObject | Element | nullbrowser viewportScroll container (element or its ref). Required when content scrolls inside an overflow: auto container.
rootMarginstring'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>.
...restHTMLAttributes<HTMLElement>—Other attributes, such as className, style and id, go to the root (the still placeholder).

アクセシビリティ

  • 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.

モーション

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.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

ScrollReveal.jsxscroll-reveal.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

リスト
「アーチ型カルーセル」は Pro に含まれます。解除するとプレビューが表示されます。
「円柱カルーセル」は Pro に含まれます。解除するとプレビューが表示されます。