A wheel of numbers that spins to its value and settles under a highlight.
Installation
Usage
<script setup lang="ts">
import {
ScrollingNumber,
ScrollingNumberContainer,
ScrollingNumberHighlight,
ScrollingNumberItems,
} from '@animate-ui/vue/primitives/texts/scrolling-number';
</script>
<template>
<ScrollingNumberContainer :number="1000" :step="100" :items-size="40">
<ScrollingNumber>
<ScrollingNumberItems />
</ScrollingNumber>
<ScrollingNumberHighlight />
</ScrollingNumberContainer>
</template>Animation
- After
delay, the strip spins through every step up tonumberon a spring (stiffness: 90, damping: 30): fast through the range, then it settles without overshoot. - A new
numbersprings on from where the strip is. - The strip is written by a motion value, without a Vue render per frame.
@number-changereports the value under the highlight as it passes. <AnimateUIProvider :tempo>paces the default spring.- Under reduced motion, the wheel lands on the number right away.
- The strip is hidden from screen readers, which read the number once from the container.
API Reference
ScrollingNumberContainer
| Prop | Type | Default |
|---|---|---|
number | number | - |
step | number | - |
items-size? | number | 30 |
side-items-count? | number | 2 |
direction? | 'btt' | 'ttb' | 'ltr' | 'rtl' | 'btt' |
@number-change? | (value: number) => void | - |
in-view? | boolean | false |
in-view-margin? | string | '0px' |
in-view-once? | boolean | true |
...props? | HTMLAttributes | - |
ScrollingNumber
| Prop | Type | Default |
|---|---|---|
delay? | number | 0 |
@completed? | () => void | - |
transition? | Transition | { stiffness: 90, damping: 30 } |
...props? | HTMLMotionProps<'div'> | - |
ScrollingNumberItems
| Prop | Type | Default |
|---|---|---|
...props? | HTMLAttributes | - |
ScrollingNumberHighlight
| Prop | Type | Default |
|---|---|---|
...props? | HTMLAttributes | - |
useScrollingNumber
Returns the container's state inside it (number, step, range, direction, isInView…).