A number that counts up (or down) to its value when it scrolls into view, and re-animates whenever the value changes — perfect for stats sections and live dashboards.
Requires the PetalNumberTicker hook from the JS bundle. The final value is
rendered server-side, so the component degrades gracefully without
JavaScript.
Summary
Functions
Renders an animated counter.
Functions
Renders an animated counter.
<.number_ticker id="stars-count" value={5200} suffix="+" class="text-4xl font-bold" />In a LiveView, updating the assign re-animates from the previous value to the new one:
<.number_ticker id="mrr" value={@mrr} prefix="$" decimal_places={2} />Attributes
id(:string) (required)value(:any) (required) - the target number (integer or float).start_value(:any) - where the first animation counts from. Defaults to0.duration(:integer) - animation length in milliseconds. Defaults to1500.decimal_places(:integer) - decimal places to show while counting. Defaults to0.prefix(:string) - e.g. "$". Defaults tonil.suffix(:string) - e.g. "+" or "%". Defaults tonil.locale(:string) - BCP 47 locale for number formatting (e.g. "de-DE"); defaults to the browser locale. Defaults tonil.class(:any) - extra classes (set font size/weight here). Defaults tonil.- Global attributes are accepted.