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 Examples

html
<!-- Global usage -->
<hy-count-to time="3600 * 30 * 1000"></hy-count-to>

Display Decimal Points

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

Thousand Separator

  • Set the thousand separator by configuring separator
html
<template>
    <hy-count-to :endVal="1542221" separator=","></hy-count-to>
</template>

Set Scrolling Duration

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

Set Font

  • Make the font bold by setting bold
  • Set the font size by configuring fontSize
  • Set the font color by configuring 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="Start" type="success" @click="start"></hy-button>
    <hy-button text="Pause" type="error" @click="pause"></hy-button>
    <hy-button text="Resume" 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 at the end when scrolling finishes, see abovebooleantrue
decimalDecimal separatorstring,
colorFont colorstring#606266
fontSizeFont size, default unit is px for numeric valuesstring|number22
boldWhether the font is boldbooleanfalse
separatorThousand separator, see abovestring-

Events

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

Methods

Event NameDescription
startStart scrolling
pausePause scrolling
resumeResume scrolling from the paused value
reStartWhile paused, restart scrolling from the beginning; or while scrolling, pause

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

03:29