---
description: https://codepen.io/shivasurya/pen/yyBoJX
---

# NumScroller, Counter From Zero To Value - Javascript Animation (ok)

### Example 0

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <section class="numbers">
    <div class="container" id="main">
      <h6 class="red-title">BY THE NUMBERS</h6>
      <h2 class="stats-heading">We’ll always measure up to your expectations</h2>
      <div class="numbers-box">
        <h1 class="count" max-data="50">30</h1>
        <h6>years of experience</h6>
      </div>
      <div class="numbers-box">
        <h1 class="count" max-data="37">0</h1>
        <h6>countires supplied</h6>
      </div>
      <div class="numbers-box">
        <h1 class="count" max-data="128">0</h1>
        <h6>group automation employees</h6>
      </div>
    </div>
  </section>
  <script>
    var runAlready;
    var counting;
    function startCounter(a) {
      runAlready = true;
      counting = true;
      $('.count').each(function () {
        var $this = $(this);
        $this.text(a);
        countTo = $this.attr('max-data');
        $({
          countNum: $this.text()
        }).animate({
          countNum: countTo
        },
        {
          duration: 2000,
          easing: 'swing',
          step: function () {
            $this.text(Math.floor(this.countNum));
          },
          complete: function () {
            $this.text(this.countNum);
            counting = false;
          }
        });
      })
    }
    $(window).scroll(function () {
      var oTop = $('#main').offset().top;
      var a = 0;
      if (!runAlready && $(window).scrollTop() > oTop || !counting && $(window).scrollTop() < oTop) {
        startCounter(a);
      }
    });
  </script>
</body>
</html>
```

```scss
.counter-box {
  display: block;
  background: #f6f6f6;
  padding: 40px 20px 37px;
  text-align: center
}
.counter-box p {
  margin: 5px 0 0;
  padding: 0;
  color: #909090;
  font-size: 18px;
  font-weight: 500
}
.counter {
  display: block;
  font-size: 32px;
  font-weight: 700;
  color: #666;
  line-height: 28px
}
.counter-box.colored {
  background: #eab736;
}
.counter-box.colored p,
.counter-box.colored .counter {
  color: #fff;
}
```



<figure><img src="https://2494213435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LYjAG13rAPdbArSfRyB%2Fuploads%2Fb6s5i9kV61ZUvwm8U8AA%2Fimage.png?alt=media&#x26;token=1ad1a01e-962f-4c5e-9d56-3eff0afc2ddd" alt=""><figcaption></figcaption></figure>

### Example 1&#x20;

{% embed url="https://www.youtube.com/watch?v=eMtebHRQaM4" %}

C:\Users\Administrator\Documents\Lorem\index.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <section id="main" class="main">
    <div class="container">
      <div class="count-heading">
        <div class="count" max-data="10">1</div>
        <h2>Project</h2>
      </div>
      <div class="count-heading">
        <div class="count" max-data="20">1</div>
        <h2>Project</h2>
      </div>
      <div class="count-heading">
        <div class="count" max-data="30">1</div>
        <h2>Project</h2>
      </div>
      <div class="count-heading">
        <div class="count" max-data="40">1</div>
        <h2>Project</h2>
      </div>
    </div>
  </section>
  <script>
    var count = document.getElementsByClassName("count");
    var inc = [];
    function intervalFunc() {
      for (let i = 0; i < count.length; i++) {
        inc.push(1);
        if (inc[i] != count[i].getAttribute("max-data")) {
          inc[i]++;
        }
        count[i].innerHTML = inc[i];
      }
    }
    var main = document.getElementById("main");
    window.onscroll = function () {
      var timer = setInterval(() => {
        var topElem = main.offsetTop;
        var btmElem = main.offsetTop + main.clientHeight;
        var topScreen = window.scrollY;
        var btmScreen = window.scrollY + window.innerHeight;
        // console.log(btmScreen);
        if (btmScreen > topElem && topScreen < btmElem) {
          intervalFunc();
        } else {
          clearInterval(timer);
          for (let i = 0; i < count.length; i++) {
            count[i].innerHTML = 1;
            inc = [];
          }
        }
      }, 100);
    }
  </script>
</body>
</html>
```

C:\Users\Administrator\Documents\Lorem\style.scss

```scss
body {
  padding: 0;
  margin: 0;
  height: 1500px;
}
.main {
  background-color: #fff;
  padding: 20px 0;
}
.container {
  padding: 0 5%;
  margin: 0 auto;
  display: flex;
}
.count-heading {
  flex: 1;
  font-size: 40px;
  text-align: center;
  border: 2px solid red;
  background-color: pink;
  color: #fff;
}

```

<figure><img src="https://2494213435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LYjAG13rAPdbArSfRyB%2Fuploads%2FuvBof877dSJhEAxTSulw%2Fimage.png?alt=media&#x26;token=9f23f499-df37-47dc-97c9-f6c4228d2ef5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2494213435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LYjAG13rAPdbArSfRyB%2Fuploads%2F6YdWLMCXYVBSkvYc9mRm%2Fimage.png?alt=media&#x26;token=de87770b-4a05-4aa2-ad72-72192bcaf365" alt=""><figcaption></figcaption></figure>

### Example 2

```
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="test4.css">
  <title>Document</title>
</head>

<body>
  <a href="https://www.i-visionblog.com/2022/05/odometerjs-animated-number-counter-from.html" class="linker">New Updated Tutorial: Odometer.js Animated Number Counter From Zero To Value - JavaScript Animation Part 2 - i-visionblog </a>
  <div class="shiva">
    <div class="shiva__left">
      <span class="count">200</span><span class="text">Text</span>
    </div>
    <div class="shiva__right">
      Lorem, ipsum, dolor.
    </div>
  </div>
  <div class="shiva">
    <div class="shiva__left">
      <span class="count">1000</span><span class="text">Text</span>
    </div>
    <div class="shiva__right">
      Lorem, ipsum, dolor.
    </div>
  </div>
  <div class="shiva">
    <div class="shiva__left">
      <span class="count">853</span><span class="text">Text</span>
    </div>
    <div class="shiva__right">
      Lorem, ipsum, dolor.
    </div>
  </div>
  <div class="shiva">
    <div class="shiva__left">
      <span class="count">154</span><span class="text">Text</span>
    </div>
    <div class="shiva__right">
      Lorem, ipsum, dolor.
    </div>
  </div>
  <div class="shiva">
    <div class="shiva__left">
      <span class="count">10</span><span class="text">Text</span>
    </div>
    <div class="shiva__right">
      Lorem, ipsum, dolor.
    </div>
  </div>
  <div class="shiva">
    <div class="shiva__left">
      <span class="count">87</span><span class="text">Text</span>
    </div>
    <div class="shiva__right">
      Lorem, ipsum, dolor.
    </div>
  </div>
  <div style="clear:both"></div>
  <div id="talkbubble"><span class="count">1421</span></div>
  <div id="talkbubble"><span class="count">145</span></div>
  <div id="talkbubble"><span class="count">78</span></div>
  <br />
  <br />
  <a class="linker" href="http://www.i-visionblog.com/2014/11/jquery-animated-number-counter-from-zero-to-value-jquery-animation.html" target="_blank">visit Tutorial in Blog</a>
  <br />
  <script src="//code.jquery.com/jquery-3.7.1.min.js"></script>
  <script type="text/javascript">
  $('.count').each(function() {
    $(this).prop('Counter', 0).animate({
      Counter: $(this).text()
    }, {
      duration: 4000,
      easing: 'swing',
      step: function(now) {
        $(this).text(Math.ceil(now));
      }
    });
  });
  </script>
</body>

</html>
```

```
.shiva {
  width: 100px;
  height: 100px;
  background: red;
  -moz-border-radius: 50px;
  -webkit-border-radius: 50px;
  border-radius: 50px;
  float: left;
  margin: 5px;
}
.count {
  line-height: 100px;
  color: white;
  margin-left: 30px;
  font-size: 25px;
}
#talkbubble {
  width: 120px;
  height: 80px;
  background: white;
  position: relative;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
  float: left;
  margin: 20px;
}
#talkbubble:before {
  content: "";
  position: absolute;
  right: 100%;
  top: 26px;
  width: 0;
  height: 0;
  border-top: 13px solid transparent;
  border-right: 26px solid white;
  border-bottom: 13px solid transparent;
}
.linker {
  font-size: 20px;
  font-color: black;
}
```

### Example 3

{% embed url="https://github.com/tinywall/numscroller" %}

<figure><img src="https://2494213435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LYjAG13rAPdbArSfRyB%2Fuploads%2FnFpESvrrRqSLax9R0jY4%2Fimage.png?alt=media&#x26;token=5dbf30cb-5b5f-4084-9b4d-7303d31a1838" alt=""><figcaption></figcaption></figure>
