Skip to content

RollingText ​

A display component that rolls digits and characters column by column: each digit column is a vertical 0–9 wheel that rolls to the target digit on value changes, while non-digit columns (decimal point, minus sign, letters) flip vertically.

  • value accepts a string or number; precision sets decimal places (pad / round)
  • prefix-text / suffix-text render currency symbols, units, etc.
  • duration sets the per-column roll duration; CSS variables allow further tuning
  • Digits roll along the shortest path (9 → 0 moves one step, not a full reverse sweep); digit columns always stay LTR, so 123 never renders as 321 on RTL pages
  • Accessibility: the visual columns are aria-hidden, with the full text kept in a visually hidden node; live enables polite announcements
  • Under prefers-reduced-motion transitions and flips are disabled, showing the target value directly

Basic Usage ​

Amount (¥ prefix + two decimals)

RandomizeReset

Character Columns ​

Decimal points, minus signs, percent signs and other non-digit characters roll column by column too:

Character columns

Speed and Size ​

duration controls the roll duration (ms); --oas-rolling-text-font / --oas-rolling-text-height control font size and column height:

duration=1200 / larger font

Screen Reader Announcements ​

Silent by default (aria-live="off") to avoid interrupting screen readers with frequent rolls; add live to enable announcements:

live: polite announcements

Direction and per-digit stopping ​

direction="up" / direction="down" makes digit columns always roll upward / downward (default keeps the shortest-path behavior, unchanged); stop-order gives each column an increasing delay (per-column stagger = duration × 12%) so they settle left to right:

direction=up + stop-order

Random value

Manual control start() / reset() ​

reset() stops any roll in progress and renders the current value instantly without transitions; start() replays a full roll for the current value (columns first drop to zero, then roll to the target):

start() / reset()

start()reset()

API ​

oas-rolling-text ​

Attributes ​

AttributeDescriptionTypeDefault
directionRoll direction: up (always upward) / down (always downward); default keeps the shortest path (unchanged), invalid values fall back with a devWarnstring—
durationPer-column roll duration (ms, default 600); invalid or non-positive falls back to the defaultstring—
liveBoolean; when present the screen-reader live region is polite (off by default to avoid frequent announcements)——
precisionDecimal places (0–10): pad / round; missing or invalid keeps the original textstring—
prefix-textPrefix text (e.g. a currency symbol)string—
stop-orderPer-digit stopping: each column gets an increasing delay (stagger = duration × 12%), settling left to right——
suffix-textSuffix text (e.g. a unit)string—
valueDisplay value (string; numeric property assignments reflect to the attribute)string | number—

Methods ​

MethodSignatureDescription
resetreset(): voidStops any roll in progress and renders the current value instantly without transitions
startstart(): voidReplays a full roll for the current value (columns first drop to zero / char columns empty, then roll to the target)

CSS Variables ​

CSS VariableDescriptionDefault
--oas-rolling-text-durationRoll durationvar(--oas-transition-base)
--oas-rolling-text-fontFont sizevar(--oas-font-size-xl)
--oas-rolling-text-heightColumn height1em
--oas-rolling-text-separator-colorColor of non-digit columns (decimal point / signs)var(--oas-color-text-primary)

Released under the MIT OR Apache-2.0 License.