Skip to content

NumberAnimation ​

An animation component that eases a number from its current value to the target value, stops at the target and emits oas-finish; under prefers-reduced-motion it jumps straight to the target, and disconnecting cancels the rAF without leaks.

Basic Usage ​

Default 1500ms roll from 0 to target

Speed and Decimal Places ​

duration=3000 + to-fixed=2

Start Value (from) ​

from sets the start value of each new round (default 0). Changing value mid-animation still continues from the currently displayed value — from does not affect continuation.

from=500 start

Controlled Playback (active + play()) ​

active controls playback: plays by default; "false" freezes the frame, changing back to "true" continues from the current value to the target. play() manually replays a round (starting from from; re-entrant safe while playing) — replay with the same value works for data refreshes without mutating value. To animate only when scrolled into view, feed active from an IntersectionObserver. The second example in the block statically shows the active="false" frozen state (held at the start value 6666).

active pause/resume + play() replay

PauseReplay

Easing ​

easing is a five-level enum: ease-out (default, fast then slow) / linear (constant speed, e.g. download bytes) / ease-in / ease-in-out / spring (mild overshoot bounce); invalid values fall back to ease-out.

easing five levels compared

Thousands Separator ​

group-separator="true" formats the animated value with locale-aware thousands separators (Intl.NumberFormat, aware of config-provider / setLocale; the formatter is cached per locale|decimals — zero per-frame construction cost).

group-separator thousands

Finish Event ​

oas-finish callback

Font Size ​

Font size is fixed at --oas-font-size-lg (16px) by default and does not follow the outer context; override with the CSS variable --oas-number-animation-font (e.g. 32px).

API ​

oas-number-animation ​

Attributes ​

AttributeDescriptionTypeDefault
activeControlled playback: plays by default; "false" freezes the frame, changing back to "true" continues from the current value to the targetstring—
durationAnimation duration (ms); 0 jumps straight to the targetnumber | string—
easingEasing: ease-out (default) / linear / ease-in / ease-in-out / spring (mild overshoot); invalid values fall back to ease-outstringease-out
fromStart value (default 0); applies at each new round start, continuation unaffectedstring0
group-separatorThousands grouping ("true" enables, Intl locale-aware; disabled by default)string—
to-fixedDecimal places (Number.prototype.toFixed); when omitted, integer displaystring—
valueTarget value; invalid values treated as 0string0

Events ​

EventDescription
oas-finishEmitted once when the animation reaches the target, detail { value: target value }

CSS Variables ​

CSS VariableDefault
--oas-number-animation-fontvar(--oas-font-size-lg)
  • Changing value mid-animation continues from the currently displayed value to the new target.
  • When the system enables "reduce motion", the animation is skipped and the target value is shown directly (oas-finish is still emitted).
  • On disconnect, any unfinished rAF is cancelled — no leaks.

Released under the MIT OR Apache-2.0 License.