Closed AlexanderTirik closed 4 years ago
function animateValue(id, range, duration) {
var current = document.getElementById(id).innerHTML
current = +current.slice(0, -1)
var start = current
var increment = range > 0 ? 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 == start + range) {
clearInterval(timer)
}
}, stepTime)
}
In the main content, we have a cost of shares. We need to write a function which will animate this number when we need to change it