1.小数递增
num2('pp3', 100, 2.6);
function num2(ID, speed, value) {
var pp2 = document.getElementById(ID);
if (value > 0) {
var num = 0.0;
var t = setInterval(function() {
num = Number((num+0.1).toFixed(1));
pp2.innerText = num;
console.log(pp2,'kkkk')
console.log(num,'mmm',value,'dddd')
if (num === value) {
console.log(111,'我到这了')
clearInterval(t);
}
}, speed);
} else {
pp2.innerText = value;
}
};
2.整数递增
num1('pp2', 100, 50);
function num1(ID, speed, value) {
var pp1 = document.getElementById(ID);
if (value > 0) {
var num = 0;
var t = setInterval(function() {
num++;
pp1.innerText = num;
if (num == value) {
clearInterval(t);
}
}, speed);
} else {
pp1.innerText = value;
}
}