前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jquery.countup实现数字滚动

jquery.countup实现数字滚动

作者头像
明知山
发布2020-09-03 10:46:44
5.3K0
发布2020-09-03 10:46:44
举报
文章被收录于专栏:前端开发随笔前端开发随笔

效果图

在这里插入图片描述
在这里插入图片描述
代码语言:javascript
复制
<!DOCTYPE html>
<html lang="zh">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>数字动画</title>

	<style type="text/css">
		* {
			margin: 0;
			padding: 0;
		}

		.box {
			display: flex;
			width: 100vw;
			height: 100vh;
			background: lightblue;
		}

		.count {
			position: relative;
			font-size: 100px;
			font-weight: 600;
			color: #268F81;
			margin: auto;
			letter-spacing: 5px;
			display: flex;
		}

		.item {
			background: #FFF;
			text-align: center;
			border-left: 1px solid #CCCCCC;
			border-right: 1px solid #CCCCCC;
			margin: 0 2px;
		}
	</style>
</head>

<body>
	<div class="box">
		<span class="count">6849874165182</span>
	</div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/waypoints/4.0.1/jquery.waypoints.min.js"></script>
<script src="http://sucai.suoluomei.cn/sucai_zs/file/20191112160050-jquery.countup.min.js"></script>

<script>
	var count = '6849874165182'
	var split = count.split('')
	var num = ''
	new Promise(function (resolve, reject) {
		split.forEach(function (i) {
			num += `<div class="item">${i}</div>`
		})
		$('.count').html(num)
		resolve(num)
	}).then(res => {
		$('.count .item').countUp({
			delay: 10,//动画延迟执行
			time: 2000//动画持续时间
		});
	})
</script>
<script>
	// 可以直接写
	// $('.count').countUp({
	// 	delay: 10,
	// 	time: 2000
	// });
</script>

</html>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-11-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档