Skip to content

数值动画 NumberAnimation


数值播放动画


基本使用

Show Code
vue
<template>
  <Row>
    <Col :span="12">
      <Statistic title="一个小目标">
        <NumberAnimation :to="100000000.12345" />
      </Statistic>
    </Col>
    <Col :span="12">
      <Statistic title="一个小目标">
        <NumberAnimation :to="100000000.12345" separator="" />
      </Statistic>
    </Col>
  </Row>
</template>

精度

Show Code
vue
<template>
  <Row>
    <Col :span="12">
      <Statistic title="一个小目标">
        <NumberAnimation :from="0.00" :to="100000000.12345" :precision="2" />
      </Statistic>
    </Col>
    <Col :span="12">
      <Statistic title="一个小目标">
        <NumberAnimation :to="100000000.12345" :precision="3" />
      </Statistic>
    </Col>
  </Row>
</template>

自定义前缀 & 后缀

Show Code
vue
<template>
  <Row>
    <Col :span="12">
      <Statistic title="一个小目标">
        <NumberAnimation
          prefix="$"
          :from="0"
          :to="100000000" />
      </Statistic>
    </Col>
    <Col :span="12">
      <Statistic title="一个小目标">
        <NumberAnimation
          :from="0"
          :to="100000000"
          suffix="元" />
      </Statistic>
    </Col>
  </Row>
</template>

自定义样式

Show Code
vue
<template>
  <Statistic title="一个小目标">
    <NumberAnimation
      :value-style="{fontSize: '30px', fontWeight: 600, color: '#d4380d'}"
      :from="0"
      :to="100000000" />
  </Statistic>
</template>

自定义播放和动画时间

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

function onStarted () {
  console.log('started')
}
function onFinished () {
  console.log('finished')
}
const animationRef = ref()
function onClick () {
  animationRef.value.play()
}
</script>
<template>
  <Statistic title="一个小目标">
    <NumberAnimation
      ref="animationRef"
      :from="0"
      :to="100000000"
      :duration="5000"
      :precision="2"
      :autoplay="false"
      @started="onStarted"
      @finished="onFinished" />
  </Statistic>
  <Button @click="onClick">播放</Button>
</template>

APIs

参数说明类型默认值必传
from数值动画起始数值number0false
to数值目标值number1000false
duration数值动画持续时间,单位msnumber3000false
autoplay是否自动开始动画booleantruefalse
precision精度,保留小数点后几位number0false
prefix前缀string''false
suffix后缀string''false
separator千分位分隔符string','false
decimal小数点字符string'.'false
valueStyle数值文本样式CSSProperties{}false
transition动画过渡效果TransitionFuncTransitionFunc['easeInOutCubic']false

Methods

事件名称说明参数
play播放动画() => void

Events

事件名称说明参数
started动画开始播放() => void
finished动画播放完成() => void

Released under the MIT License.