Ir al contenido
Español

Cómo funciona

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.

Úsalo para

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

Busca otra opción cuando

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

Uso

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

Propiedades

PropiedadTipoPor defectoQué hace
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.

Accesibilidad

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

Movimiento

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.

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.

RollingNumber.jsxrolling-number.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.

Datos
Diferencias de código viene con Pro. La vista previa aparece al desbloquearlo.
Cuenta atrás con flip viene con Pro. La vista previa aparece al desbloquearlo.