Skip to content

CountTo Number Animation

Used for animated number display, supporting themes, prefixes/suffixes, decimal precision, and manual control.

Component Type

Basic Usage

Set end-val to specify the final value, start-val for the starting value, and duration for the animation duration (ms).

html
<wd-count-to :end-val="2024" suffix="Year" color="#16baaa" />
<wd-count-to prefix="¥" :start-val="0" :decimals="2" :end-val="186.321" suffix="%" color="#1e9fff" />
<wd-count-to prefix="¥" :start-val="0" :decimals="2" :end-val="21286.321" suffix="%" color="#ff5722" />
<wd-count-to prefix="¥" :start-val="0" :decimals="2" :end-val="21286.321" suffix="%" color="#ffb800" :duration="2000" />

Component Style

Set Theme

Set the text theme via type. Optional values are default, primary, success, warning, error.

html
<wd-count-to type="primary" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />
<wd-count-to type="error" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />
<wd-count-to type="success" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />
<wd-count-to type="warning" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />
<wd-count-to type="default" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />

Special Style

Manual Control

After setting auto-start="false", you can manually start, pause, and reset via instance methods.

html
<wd-count-to ref="countTo" :auto-start="false" prefix="¥" :start-val="1000" :decimals="3" :end-val="9999.32" suffix="%" color="#1e9fff" />
<wd-grid clickable border>
  <wd-grid-item text="Start" icon="play-circle" @click="start" />
  <wd-grid-item text="Pause" icon="pause-circle" @click="pause" />
  <wd-grid-item text="Reset" icon="refresh" @click="reset" />
</wd-grid>
ts
import type { CountToInstance } from '@/uni_modules/wot-ui/components/wd-count-to/types'

const countTo = ref<CountToInstance>()

const start = () => countTo.value?.start()
const pause = () => countTo.value?.pause()
const reset = () => countTo.value?.reset()

Attributes

ParameterDescriptionTypeDefault Value
colorText colorstring''
type v1.3.9Theme type, optional values are default, primary, success, warning, errorstringdefault
start-valStarting valuenumber0
end-valFinal valuenumber2024
durationAnimation duration from start to end value (milliseconds)number3000
auto-startWhether to start automaticallybooleantrue
decimalsNumber of decimal places to retain, must be >= 0number0
decimalDecimal point symbolstring.
separatorThousands separatorstring,
prefixPrefix textstring''
suffixSuffix textstring''
use-easingWhether to use easing animationbooleantrue
custom-classCustom class name for root nodestring''
custom-styleCustom style for root nodestring''

Events

Event NameDescriptionParameters
mountedTriggered when component loading is complete-
finishTriggered when animation is complete-

Methods

Method NameDescriptionParameters
startStart animation-
pausePause animation-
resetReset animation; if auto-start is true, automatically starts after reset-

Slots

NameDescriptionParameters
defaultMain number content-
prefixPrefix content-
suffixSuffix content-

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-count-to-text-font-size$typography-body-size-ultra-large数字主体文本字号
--wot-count-to-text-line-height$typography-body-line--height-size-ultra-large数字主体文本行高
--wot-count-to-separator-text-font-size$typography-label-size-main分隔文本字号
--wot-count-to-separator-text-line-height$typography-label-line--height-size-main分隔文本行高

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.