I’ve tried everything I can find online about this but they all seem to deal with static numbers, not animated numbers.
Is it possible to have commas added to my values as the number increases using this by modifying this function?
animateCounter(element) {
let counter = 0;
let increment = 1;
const matches = /(+)?(d+)(w)?/.exec(element.dataset.count);
const before = matches[1] ?? '';
const after = matches[3] ?? '';
if (matches[2] > 1000) {
increment = 50;
} else if (matches[2] > 100) {
increment = 10;
}
const step = timestamp => {
counter += increment;
element.innerText = `${before}${counter}${after}`;
if (counter < +matches[2]) {
window.requestAnimationFrame( step );
}
}
window.requestAnimationFrame( step );
}
New contributor
Richmond Solution is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.