【前端】countUp.js 实现数字滚动 动态效果【JS版】

本文展示如何使用CountUp.js库实现网页上数字的平滑增长动画效果,包括配置选项和示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

演示地址

http://inorganik.github.io/countUp.js/
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/countup.js/1.9.3/countUp.js"></script>
</head>
<body>
<h1 id="num1"></h1>
<h1 id="num2"></h1>
<h1 id="num3"></h1>

<script type="text/javascript">
    var options = {
        useEasing: true, 	 	// 使用缓和
        useGrouping: true,	// 使用分组(是否显示千位分隔符,一般为 true)
        separator: ',',		// 分隔器(千位分隔符,默认为',')
        decimal: '.',			// 十进制(小数点符号,默认为 '.')
        prefix: '',			// 字首(数字的前缀,根据需要可设为 $,¥,¥ 等)
        suffix: ''			// 后缀(数字的后缀 ,根据需要可设为 元,个,美元 等) 
    };
    $(function () {
        // CountUp(参数一, 参数二, 参数三, 参数四, 参数五, 参数六)
        // 参数一: 数字所在容器
        // 参数二: 数字开始增长前的默认值(起始值),一般从 0 开始增长
        // 参数三: 数字增长后的最终值,该值一般通过异步请求获取
        // 参数四: 数字小数点后保留的位数
        // 参数五: 数字增长特效的时间,此处为3秒
        // 参数六: 其他配置项
        // 注: 参数六也可不加,其配置项则为默认值

        new CountUp("num1", 0, 1380, 0, 3, options).start();
        new CountUp("num2", 0, 1380, 2, 3, options).start();
        new CountUp("num3", 0, 1380, 4, 3, options).start();
    });
</script>

</body>
</html>

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

区块链(Web3)开发工程师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值