js代碼 簡單實現數字滾動增長動效(原)

<html>
<body>javascript

<span>look this:</span><span id="nums">10000</span>html

</body>java

</heml>函數

<script type="text/javascript">
var totalNum = 10000;
var nums = 0;
// 調用計時函數
setTimeout(timedCount(nums),50);

// 循環計時函數, 屢次調用自身函數, nums爲被傳遞的參數
function timedCount(nums){
var count = Math.round(totalNum/97);
nums = nums+count;
document.getElementById('nums').innerHTML =nums
// $("#nums").text(nums);
// 設置條件使中止計時
if (nums<totalNum) {
setTimeout(function(){timedCount(nums)},50);
}else{
document.getElementById('nums').innerHTML =totalNum
}
}this


</script>spa

相關文章
相關標籤/搜索