Skip to content

数值动画 NumberAnimation

数值播放动画


Play

基本使用

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>

自定义播放和动画时间

播放
一个小目标
0.00
Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'
const animationRef = ref()
const from = ref(0)
const to = ref(100000000)
function onClick () {
  animationRef.value.play()
}
function onStarted () {
  console.log('started')
}
function onFinished() {
  console.log('finished');
  [from.value, to.value] = [to.value, from.value]
}
</script>
<template>
  <Space vertical>
    <Button type="primary" @click="onClick">播放</Button>
    <Statistic title="一个小目标">
      <NumberAnimation
        ref="animationRef"
        :from="from"
        :to="to"
        :duration="5000"
        :precision="2"
        :autoplay="false"
        @started="onStarted"
        @finished="onFinished"
      />
    </Statistic>
  </Space>
</template>

APIs

NumberAnimation

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

Methods

名称说明类型
play播放动画() => void

Events

名称说明类型
started动画开始播放() => void
finished动画播放完成() => void

Released under the MIT License.