I have made a simple count up animation in JS that just simply counts up incrementally to the set target. I would like to add commas and found this on code on another form, the comma works but the animation doesn't work now. Any help is greatly appreciated.
counterss.forEach(counters => {
const updateCount = () => {
const target = +counters.getAttribute('data-target');
const count = +counters.innerText;
// Lower inc to slow and higher to slow
const inc = 1;
// console.log(inc);
// console.log(count);
// Check if target is reached
if (count < target) {
// Add inc to count and output in counter
counters.innerText = count + inc;
// Call function every ms
setTimeout(updateCount, 10000);
}
if
else {
const updateCount = (x) => {
var counterss = x.counters().split(".");
parts[0] = parts[0].replace(/B(?=(d{3})+(?!d))/g, ",");
return parts.join(".");
} else {
counters.innerText = target;
}
};
updateCount();
});
<section class="counterss section-size" style="color:white; text-align:center;">
<div class="container">
<div style="align-content:center;">
<h4 class="counters" style="position:relative; color:white; text-align:center; font-size:90px; padding: 3% 0 0 0; margin:auto;" data-target="20000">13,854</h3>
<h4 style="color:white; text-align:center; top:50%; font-size:35px; position: relative; margin: auto; ">Lorem Ipsum</h3>
</div>
</div>
</section>
question from:
https://stackoverflow.com/questions/65847087/javascript-number-count-up-with-commas 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…