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

Update animation of shares. Shares should change color when they changing #18

Closed AlexanderTirik closed 4 years ago

AlexanderTirik commented 4 years ago

We need to improve the animation of stock price changes. So that when the stocks decreased, they were red, with an increase they became green.

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)
  if (range > 0) {
    obj.style.color = "green"
  } else {
    obj.style.color = "red"
  }
  var timer = setInterval(function () {
    current += increment
    obj.innerHTML = current + "$"
    if (current == start + range) {
      clearInterval(timer)
    }
  }, stepTime)
}

export { animateValue }