A number whose digits roll to their new value, like an odometer.
Installation
Usage
<script setup lang="ts">
import { SlidingNumber } from '@animate-ui/vue/primitives/texts/sliding-number';
defineProps<{ value: number }>();
</script>
<template>
<SlidingNumber :number="value" thousand-separator="," />
</template>Animation
- Each digit sits on a wheel that springs to its new value (
stiffness: 200, damping: 20, mass: 0.4), straight through the digits in between: going from 9 to 0, it rolls back through 8, 7… - With
from-number, the number counts tonumberon a spring (stiffness: 90, damping: 50), every digit rolling on the way; a newnumberthen counts on from the current value. Without it, the digits roll straight to their new value. - Digits are positioned in percentages of their own height: no measuring, right on the first frame and when the font size changes. Counting doesn't re-render Vue per frame.
<AnimateUIProvider :tempo>paces the default springs.- Under reduced motion, the digits change without rolling.
- Screen readers read the number once, not every rolled digit.
API Reference
SlidingNumber
| Prop | Type | Default |
|---|---|---|
number | number | - |
from-number? | number | - |
@number-change? | (number: number) => void | - |
pad-start? | boolean | false |
decimal-separator? | string | '.' |
decimal-places? | number | 0 |
thousand-separator? | string | - |
transition? | SpringOptions | { stiffness: 200, damping: 20, mass: 0.4 } |
delay? | number | 0 |
initially-stable? | boolean | false |
in-view? | boolean | false |
in-view-margin? | string | '0px' |
in-view-once? | boolean | true |
...props? | Omit<HTMLMotionProps<'span'>, 'children'> | - |