Skip to content

CountTo Number Scrolling Component ​

This component is generally used in scenarios where a number needs to be scrolled to a specific value; the target is required to be an incrementing value.

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage ​

html
<!-- 全局使用 -->
<hy-count-to time="3600 * 30 * 1000"></hy-count-to>

Displaying Decimal Points ​

  • Set the number of decimal places via decimals
html
<template>
    <hy-count-to :endVal="1542221" :decimals="2"></hy-count-to>
</template>

Thousands Separator ​

  • Set the thousands separator via separator
html
<template>
    <hy-count-to :endVal="1542221" separator=","></hy-count-to>
</template>

Setting Scroll Duration ​

  • Set the scrolling duration via duration
html
<template>
    <hy-count-to :endVal="1542221" :duration="10000"></hy-count-to>
</template>

Setting the Font ​

  • Make the font bold via bold
  • Set the font size via fontSize
  • Set the font color via color
html
<template>
    <hy-count-to :endVal="154" bold fontSize="40" color="#31E749"></hy-count-to>
</template>

Manual Control ​

html
<hy-count-to ref="countToRef" :endVal="1542222" :duration="10000" :autoplay="false"></hy-count-to>
<view class="hy-flex">
    <hy-button text="开始" type="success" @click="start"></hy-button>
    <hy-button text="暂停" type="error" @click="pause"></hy-button>
    <hy-button text="继续" type="info" @click="resume"></hy-button>
</view>
ts
import HyCountTo from 'hy-app/components/hy-count-to/hy-count-to.vue';
import { ref } from 'vue';

const countToRef = ref<InstanceType<typeof HyCountTo>>();

const start = () => {
    if (countToRef.value) {
        countToRef.value.start();
    }
};

const pause = () => {
    if (countToRef.value) {
        countToRef.value.pause();
    }
};

const resume = () => {
    if (countToRef.value) {
        countToRef.value.resume();
    }
};
scss
.hy-flex {
    display: flex;
    justify-content: space-around;
}

API ​

CountTo ​

ParameterDescriptionTypeDefault
startValStart valuenumber0
endValEnd valuenumber0
durationTime required for the scrolling process, in msnumber2000
autoplayWhether to start scrolling automaticallybooleantrue
decimalsNumber of decimal places to display, see abovenumber0
useEasingWhether to ease the ending when scrolling finishes, see abovebooleantrue
decimalDecimal separatorstring,
colorFont colorstring#606266
fontSizeFont size, numeric values default to pxstring|number22
boldWhether the font is boldbooleanfalse
separatorThousands separator, see abovestring-

Events ​

Event NameDescriptionCallback Parameters
endTriggered when the value scrolls to the target value-

Methods ​

NameDescription
startStart scrolling
pausePause scrolling
resumeResume scrolling from the paused value
reStartWhen paused, restart scrolling; or when scrolling, pause

CSS Variables ​

VariableDescriptionDefault
--hy-count-to-colorNumber text colorFollows --hy-text-color

[^1] DD-day, HH-hour, mm-minute, ss-second, SSS-millisecond

12:33
battery