Skip to content

CountTo

基础用法

html

<pa-count-to
  ref="countToRef"
  :start-num="0"
  :end-num="999"
  custom-class="text-60 text-black"
  @click="countToRef?.restart()"
/>
ts

import { ref } from 'vue'
import type { CountToInstance } from '../..'

const countToRef = ref<CountToInstance>()

倒计时

html

<pa-count-to
  ref="countToRef"
  :start-num="999"
  :end-num="0"
  custom-class="text-60 text-black"
  @click="countToRef?.restart()"
/>
ts

import { ref } from 'vue'
import type { CountToInstance } from '../..'

const countToRef = ref<CountToInstance>()

显示小数

html

<pa-count-to
  ref="countToRef"
  :start-num="0"
  :end-num="999.99"
  custom-class="text-60 text-black"
  @click="countToRef?.restart()"
/>
ts

import { ref } from 'vue'
import type { CountToInstance } from '../..'

const countToRef = ref<CountToInstance>()

自定义格式化值

html

<pa-count-to
  ref="countToRef"
  :start-num="0"
  :end-num="9999"
  :formatter="formatter"
  custom-class="text-60 text-black"
  @click="countToRef?.restart()"
/>
ts

import { ref } from 'vue'
import type { CountToInstance } from '../..'

const countToRef = ref<CountToInstance>()

const formatter = (num: number) => {
  return num.toString().replace(/\d+/, (s) => {
    return s.replace(/(\d)(?=(\d{3})+$)/g, '<!--codes start-->,')
  })
}

自定义控制

html

<pa-count-to ref="countToRef" :start-num="0" :end-num="999" custom-class="text-60 text-black" />
<view class="grid grid-cols-3 gap-20 mt-30">
  <pa-button block @click="countToRef?.start">开始</pa-button>
  <pa-button block @click="countToRef?.pause">暂停</pa-button>
  <pa-button block @click="countToRef?.resume">继续</pa-button>
  <pa-button block @click="countToRef?.reset">重置</pa-button>
  <pa-button block @click="countToRef?.restart">重新开始</pa-button>
</view>
ts

import { ref } from 'vue'
import type { CountToInstance } from '../..'

const countToRef = ref<CountToInstance>()

CountTo Props

参数说明类型默认值
startNum开始值number0
endNum结束值number100
duration滚动过程所需的时间,单位msnumber2000
frequency频率,默认保持每秒60帧,即16毫秒一次number16
autoplay是否自动开始滚动boolean-
easeout缓动结尾效果booleantrue
formatter格式化值(value:number)=>string|number-
customClass自定义classstring-
customStyle自定义stylestring|CSSProperties-

CountTo Event

事件名参数
click(value: Event)
change(value: number, progress: number)
finish()

CountTo Slot

名称说明

样式变量

🙈