Can I know what’s wrong in the below code ?
For some reason the numbers are not counting on loading
$w.onReady(function() {
function countElement(element, startValue, endValue, prefix = "", suffix = "") {
const duration = 2000;
const increment = (endValue - startValue) / (duration / 20);
let currentValue = startValue;
const timer = setInterval(() => {
currentValue += increment;
$w(element).text = prefix + `${(Math.round(currentValue)).toLocaleString('en-US')}${suffix}`;
if (currentValue >= endValue) {
clearInterval(timer);
}
}, 20);
}
$w('#startCounting').onViewportEnter(async () => {
await countElement("#numberOne", 0, 10,"","");
await countElement("#numberTwo", 0, 500,"","+");
await countElement("#numberThree", 15000, 20000,"$","");
})
});