I have a count up code here:
HTML:
<div id="value">700</div>
<div id="value2">1000</div>
JavaScript:
function animateValue(id, start, end, duration) {
var start= 0 ;
var end = parseInt(document.getElementById(id).textContent, 10);
var duration = 10000;
var range = end - start;
var current = start;
var increment = end > start? 1 : -1;
var stepTime = Math.abs(Math.floor(duration / range));
var obj = document.getElementById(id);
var timer = setInterval(function() {
current += increment;
obj.innerHTML = current;
if (current == end) {
clearInterval(timer);
}
}, stepTime);
}
animateValue("value2",0,0,0);
animateValue("value",0,0,0);
In this code numbers start from 0 to end with 10000ms duration. How can I set this duration be slower than this when it's close to the end?
For example:
Numbers: 0 To 100.
Duration : 50ms To 10ms.