Check out the code snippet below for a cool example:
let a = 0;
$(window).scroll(function () {
let oTop = $('#counter').offset().top - window.innerHeight;
if (a == 0 && $(window).scrollTop() > oTop) {
$('.counter').each(function () {
let $this = $(this);
jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
duration: 2000,
easing: 'swing',
step: function () {
$this.text(Math.ceil(this.Counter));
}
});
});
a = 1;
}
});
.text-center {
text-align: center;
}
.statistics {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 20px;
}
.statistics .stastic{text-align: center;background-color: bisque;}
.statistics .stastic h4{font-size: 24px;}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"
integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
crossorigin="anonymous" referrerpolicy="no-referrer></script>
<title>Document</title>
<style>
.text-center {
text-align: center;
}
.statistics {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 20px;
}
.statistics .stastic{text-align: center;background-color: bisque;}
.statistics .stastic h4{font-size: 24px;}
</style>
</head>
<body>
<p class="text-center">Scroll Down</p>
<!-- Snippet with counter stats starts here -->
<section id="counter" class="statistics">
<div class="stastic">
<h4 class="counter">500</h4>
<p>Projects Done</p>
</div>
<div class="stastic">
<h4 class="counter">10</h4>
<p>Years Experience</p>
</div>
<div class="stastic">
<h4 class="counter percent">100</h4>
<p>Success Rate</p>
</div>
</section>
<!-- End of counter stats -->
<p class="text-center">Lorem Ipsum is simply dummy text...</p>
</body>
</html>