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.
valueaccepts a string or number;precisionsets decimal places (pad / round)prefix-text/suffix-textrender currency symbols, units, etc.durationsets the per-column roll duration; CSS variables allow further tuning- Digits roll along the shortest path (
9 → 0moves one step, not a full reverse sweep); digit columns always stay LTR, so123never renders as321on RTL pages - Accessibility: the visual columns are
aria-hidden, with the full text kept in a visually hidden node;liveenables polite announcements - Under
prefers-reduced-motiontransitions and flips are disabled, showing the target value directly
Basic Usage
Amount (¥ prefix + two decimals)
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
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()
API
oas-rolling-text
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
direction | Roll direction: up (always upward) / down (always downward); default keeps the shortest path (unchanged), invalid values fall back with a devWarn | string | — |
duration | Per-column roll duration (ms, default 600); invalid or non-positive falls back to the default | string | — |
live | Boolean; when present the screen-reader live region is polite (off by default to avoid frequent announcements) | — | — |
precision | Decimal places (0–10): pad / round; missing or invalid keeps the original text | string | — |
prefix-text | Prefix text (e.g. a currency symbol) | string | — |
stop-order | Per-digit stopping: each column gets an increasing delay (stagger = duration × 12%), settling left to right | — | — |
suffix-text | Suffix text (e.g. a unit) | string | — |
value | Display value (string; numeric property assignments reflect to the attribute) | string | number | — |
Methods
| Method | Signature | Description |
|---|---|---|
reset | reset(): void | Stops any roll in progress and renders the current value instantly without transitions |
start | start(): void | Replays a full roll for the current value (columns first drop to zero / char columns empty, then roll to the target) |
CSS Variables
| CSS Variable | Description | Default |
|---|---|---|
--oas-rolling-text-duration | Roll duration | var(--oas-transition-base) |
--oas-rolling-text-font | Font size | var(--oas-font-size-xl) |
--oas-rolling-text-height | Column height | 1em |
--oas-rolling-text-separator-color | Color of non-digit columns (decimal point / signs) | var(--oas-color-text-primary) |