Skip to content

Instantly share code, notes, and snippets.

@elkcityhazard
elkcityhazard / coolDownCounter.js
Last active July 5, 2024 14:18
Implement the classic counter that slows down as it gets closer to it's limit (I call it a cooldown timer)
class CountUp {
constructor(elID = "", currentIndex = 0, limit = 100, baseInterval = 30, coolDown = 90) {
this.elID = elID
this.element = document.getElementById(elID)
this.currentIndex = +currentIndex
this.limit = +this.element.dataset['count']
this.baseInterval = +baseInterval
this.coolDown = +coolDown
this.percentOf = Math.floor(this.limit * this.coolDown / 100)
this.initCountUp()