AlexanderTirik / homepage

My very own personal website. Basically this is just a résumé.
https://alexandertirik.github.io/homepage/
MIT License
0 stars 1 forks source link

Add animation of counting #14

Closed AlexanderTirik closed 4 years ago

AlexanderTirik commented 4 years ago

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

AlexanderTirik commented 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)
}