本文へ移動
日本語

仕組み

Each digit is a window showing one cell of a vertical 0–9 strip, moved to the target with translateY. Neighbouring digits start a few dozen milliseconds apart, from the ones place upward, which reads like a carry. The number waits at 0 until it is in view (IntersectionObserver), then rolls up; later changes roll from the old digit to the new one and never pass back through 0. Tabular digits keep the width steady and a mask fades the top and bottom edges. Pure CSS transitions, no timers. The demo is a live sales card: each new order rolls the total and the delta, grows the current hour's bar and slides into the panel below.

向いている場面

  • Key figures such as balances, visits or order counts where the change itself matters.
  • Dashboards and widgets where numbers should roll in when they first come into view.

向かない場面

  • Many numbers changing at once in a table: it looks noisy, just replace the text.
  • Live data refreshing several times a second: the animation cannot finish.

使い方

import { RollingNumber } from './RollingNumber.jsx'

export function SalesToday({ total, delta }) {
  return (
    <div style={{ fontSize: 40, fontWeight: 700, letterSpacing: '-0.03em' }}>
      $<RollingNumber value={total} duration={700} />
      <small>
        <RollingNumber value={delta} decimals={1} />%
      </small>
    </div>
  )
}

プロパティ

プロパティ型既定値説明
valuenumber—The number to show. Rounded to `decimals` places (an integer by default).
durationnumber700Roll time of each digit, in ms.
staggernumber45Delay between neighbouring digits, in ms.
separatorbooleantrueAdds thousands separators.
decimalsnumber0Digits after the decimal point (0 to 6). Every fraction digit rolls like the others.
localestring'en-US'Locale for the separators, for example de-DE for 12.846,5.
startOnViewbooleantrueWait at 0 until at least 30% of the number is in view, then roll up. False rolls up as soon as it mounts.
blurbooleanfalseSoftens each digit with motion blur while it rolls, more for a longer roll, and sharpens it as it lands. Good for prices and balances that change on a switch.

アクセシビリティ

  • Screen readers get only the final number through aria-label, never the values in between.
  • With reduced motion, the result is shown directly.
  • Until it is in view the visible digits rest at 0, but aria-label always holds the real number.

モーション

700ms per digit on the reveal curve (cubic-bezier(0.22, 1, 0.36, 1)), 45ms between neighbouring digits; starts on first view. With blur, each rolling digit takes filter: blur() up to 0.02em + 0.008em per digit travelled (at most 0.08em), peaking at 30% of the roll and sharp again on landing; reduced motion turns it off with the roll.

プロジェクトに追加

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

RollingNumber.jsxrolling-number.csstokens.cssREADME.md

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

データ表示
「コード差分」は Pro に含まれます。解除するとプレビューが表示されます。
「フリップカウントダウン」は Pro に含まれます。解除するとプレビューが表示されます。