<CountUp
end={9999}
decimals={1}
duration={3}
delay={1}
separator=','
start={0}
prefix='中华人民共和国国土面积:'
suffix='平方公里'
onEnd={() => {
console.log('动画结束');
}}
onStart={() => {
console.log('动画开始');
}}
/>
import { useState } from 'react';
import styles from './style.less'
import CountUp from 'react-countup';
const index = () => {
const [numbers, setNumbers] = useState([1, 2, 3]);
return (
<div>
<div className={styles.countUpContainer} >
{numbers.map((item: any, index) => {
return (
<div key={index} className={styles.countCore}>
<div className={styles.countBgd} style={{ padding: '2px 5px' }}>
{}
<CountUp end={item} />
</div>
</div>
)
})}
</div>
<button onClick={() => { setNumbers([...numbers, 1]) }}>添加</button>
</div >
);
}
export default index;
import { useRef } from 'react';
import { useCountUp } from 'react-countup';
const index = () => {
const countUpRef = useRef();
const { start, reset } = useCountUp({
end: 876,
prefix: '鹿邑县',
suffix: '公里',
duration: 3,
ref: countUpRef,
onEnd: ({ pauseResume, reset, start, update }) => {
console.log('加载结束');
}
});
return (
<div>
{}
<div style={{ fontSize: '32px' }} ref={countUpRef}></div>
<button onClick={() => { start(); }}>
重置动画
</button>
<button onClick={() => { reset(); }} >
重置为 0
</button>
</div>
);
};
export default index;