Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

Javascript Number Count Up with Commas

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...