PXD

Rolling Number

Display a number with a rolling animation effect, supporting decimals and thousands separators.

Default

438
<template>
  <PRollingNumber :value="999" />
</template>

Thousands

439
<template>
  <PRollingNumber :value="1000" thousands />
</template>

Durations

206
<template>
  <PRollingNumber :value="999" :durations="5000" />
</template>

With suffix

Numbers between different fonts may shake when they change, and tabular-nums class can be added to reduce the jitter.

206+ Users
<template>
  <PRollingNumber value="999+ Users" class="tabular-nums" :durations="5000" />
</template>

Scroll mode

Per-digit reel that rolls from bottom to top.

1,234
<script setup>
import { ref } from 'vue'

const number = ref(1234)

function changeValue() {
  number.value += Math.floor(Math.random() * 900) + 100
}
</script>

<template>
  <PStack direction="vertical">
    <PButton @click="changeValue">Change</PButton>

    <PRollingNumber :value="number" mode="scroll" thousands class="text-2xl tabular-nums" />
  </PStack>
</template>

Without mount animation

999
<script setup>
import { ref } from 'vue'

const number = ref(999)

function changeValue() {
  number.value += 999
}
</script>

<template>
  <PStack direction="vertical">
    <PButton @click="changeValue">Change</PButton>

    <PRollingNumber :value="number" :animate-on-mount="false" class="block" />
  </PStack>
</template>

Props

NameTypeDefaultDescription
valuenumber | string0Target number. A string may include a numeric prefix plus unit/suffix (e.g. "999+ Users").
durationsnumber2000Animation duration in milliseconds.
animateOnMountbooleantrueWhether to play the animation on first mount. When false, the initial value is shown as-is; later value changes still animate.
thousandsbooleanfalseFormat the integer part with thousand separators.
mode'tween' | 'scroll''tween'tween interpolates the value; scroll rolls each digit

Events

NameTypeDescription
finish() => voidEmitted when the animation finishes on the target value.

Methods

NameTypeDescription
displayValuenumberThe value the running animation is currently displaying.
formattedValuestringdisplayValue formatted with the current decimal places and thousands setting.

Source

Source