码迷,mamicode.com
首页 > 其他好文 > 详细

页面数字动态增长至目标值

时间:2018-06-20 14:26:35      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:html   timeout   跳转   +=   out   else   title   func   get   

<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="../js/common.js"></script>
</head>
<body>
<span id="a666"></span>
<script type="text/javascript">
con_IncreaseToNumber("a666",100086.10086,10000)

//数字跳转增长 目标id,跳转目标数值,跳转总时间
function con_IncreaseToNumber(id, number, timeSpan) {
var dom = document.getElementById(id);
//时间,默认2s;
var timeSpan = timeSpan || 2000;
var n = timeSpan / 100;
//频率
var degreen = parseInt(parseInt(number) / n);
var curValue = 0;
(function numberIncreaseTo() {
setTimeout(function() {
if (curValue < number) {
var tmpValue = curValue;
if ((tmpValue += degreen) < number) {
(curValue = tmpValue);
dom.innerHTML = tmpValue;
numberIncreaseTo();
} else {
(curValue = number);
dom.innerHTML = curValue;
}
}
}, 100);
})()
}


</script>
</body>
</html>

页面数字动态增长至目标值

标签:html   timeout   跳转   +=   out   else   title   func   get   

原文地址:https://www.cnblogs.com/ygxthink/p/9203124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!