This script animates numbers from 0 β target value when the element scrolls into view.
Each counter uses a data attribute:
<span class="counter" data-target="500">0</span>
π To edit:
counterdata-target="500"
to any number (e.g. 1000, 250, 75)
duration: 2,
π Adjust:
1 = fast2 = normal (default)3+ = slowstart: "top 80%",
π Options:
"top 90%" β starts earlier"top 70%" β starts later"top 50%" β starts mid-screenonce: true
true β animation runs once β
false β repeats on scrollEdit this part:
onUpdate: function () {
counter.innerText = Math.floor(counter.innerText);
}
counter.innerText = Math.floor(counter.innerText) + "+";
counter.innerText = Math.floor(counter.innerText) + "%";
counter
data-target="300"
0
counterdata-targetβ Already fixed with:
Math.floor(counter.innerText)
Adjust:
start: "top 80%"
counterdata-targetdurationstartonUpdateβ