Counter Up Animation On Scroll using HTML, CSS & JavaScript

Counter Up Animation On Scroll using HTML, CSS & JavaScript

Hello developers, today in this blog, you'll learn how to create a Counter Up Animation On Scroll using HTML, CSS & JavaScript.

The Counter Up is a lightweight and easy-to-use javascript that dynamically counts up to a targeted number from 0 at a specific speed and time. This Counter Up Animation On Scroll would be useful when designing something like a dashboard for the website of the company.

In this Counter Up Animation On Scroll, there is a title at the center of the webpage. Below the title, there are four cards which indicate some details of the company like the count of the projects the company has done, and there is a count of happy clients, trained students of the company and count of the countries that the company has visited. Above the count, there is an icon and below there is a heading. If you refresh the page the count increases to that targeted number from 0. The JavaScript code is mainly used to make the count animated.

The source code of this Counter Up Animation On Scroll is given below, if you want the source code of this program, you can copy it. You can use this Counter Up Animation On Scroll code on your projects.

Counter Up Animation On Scroll [Source Code]

To make this website, you would like to make three files: an HTML file, a CSS file & a JavaScript file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.

<!DOCTYPE html> <html> <head> <title>Counter || Learningrobo</title> <link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> </head> <body> <div class="hero"> <div class="title"> <h1>ABOUT COMPANY</h1> </div> <div class="row"> <div class="col"> <div class="counter-box"> <i class="fa fa-BOOK"></i> <h2 class="counter">215</h2> <h4>PROJECTS</h4> </div> </div> <div class="col"> <div class="counter-box"> <i class="fa fa-users"></i> <h2 class="counter">101</h2><span>k</span> <h4>HAPPY CLIENTS</h4> </div> </div> <div class="col"> <div class="counter-box"> <i class="fa fa-USER"></i> <h2 class="counter">205</h2> <h4>TRAINED STUDENTS</h4> </div> </div> <div class="col"> <div class="counter-box"> <i class="fa fa-globe"></i> <h2 class="counter">105</h2> <h4>VISITED COUNTRIES</h4> </div> </div> </div> <div class="credit">Made with <span style="color:tomato;font-size:20px;">❤</span> by <a href="https://www.learningrobo.com/">Learning Robo</a></div> </div> <script src="http://cdnjs.cloudflare.com/ajax/libs/waypoints/2.0.3/waypoints.min.js"></script> <script src="script.js"></script> </body> </html>
CSS provides style to an HTML page. To make the page attractive and page responsive create a CSS file with the name style.css and remember that you have to make a file with a .css extension.


* {
    padding: 0;
    margin: 0;
    font-family: sans-serif;
}
.hero{
    width: 100%;
    height: 100vh;
    background-image: linear-gradient(rgba(100, 235, 161, 0.671),rgba(255, 255, 255, 0.5)),url(https://cdn.pixabay.com/photo/2018/08/21/23/29/forest-3622519__340.jpg);
    background-position: center;
    background-size: cover;
    text-align: center;
    position: relative;
}
.title{
    width: 60%;
    display: inline-block;
    margin: 150px auto 0;
    color: #000;
    text-align: center;
}
.title h1{
    margin-bottom: 30px;
}
.title p{
    font-size: 13px;
    line-height: 22px;
}
.row{
    width: 85%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translate(-50%,-50%);
}
.col{
    flex-basis: 22%;
    text-align: center;
    color: #555;
}
.counter-box{
    width: 100%;
    height: 100%;
    background: #12192c;
    padding: 20px 0;
    border-radius: 10px;
    box-shadow: 0 0 20px -4px #66676c;
    color:#fff;
}
h2,span{
    display: inline-block;
    margin: 15px 0;
    font-size: 50px;
    color: #fff;
}
.counter-box .fa{
    font-size: 40px;
    color: rgba(16, 211, 97, 0.603);
    display: block;
}
.credit a{
    text-decoration: none;
    color: #000;
  }

  .credit {
      margin-top: 10px;
      text-align: center;
  }
JavaScript makes the page work functionally which makes the count-up animation. At last, create a JavaScript file with the name of script.js and remember that you've got need to make a file with a .js extension.


(function(e){"use strict";e.fn.counterUp=function(t){var n=e.extend({time:400,delay:10},t);return this.each(function(){var t=e(this),r=n,i=function(){var e=[],n=r.time/r.delay,i=t.text(),s=/[0-9]+,[0-9]+/.test(i);i=i.replace(/,/g,"");var o=/^[0-9]+$/.test(i),u=/^[0-9]+\.[0-9]+$/.test(i),a=u?(i.split(".")[1]||[]).length:0;for(var f=n;f>=1;f--){var l=parseInt(i/n*f);u&&(l=parseFloat(i/n*f).toFixed(a));if(s)while(/(\d+)(\d{3})/.test(l.toString()))l=l.toString().replace(/(\d+)(\d{3})/,"$1,$2");e.unshift(l)}t.data("counterup-nums",e);t.text("0");var c=function(){t.text(t.data("counterup-nums").shift());if(t.data("counterup-nums").length)setTimeout(t.data("counterup-func"),r.delay);else{delete t.data("counterup-nums");t.data("counterup-nums",null);t.data("counterup-func",null)}};t.data("counterup-func",c);setTimeout(t.data("counterup-func"),r.delay)};t.waypoint(i,{offset:"100%",triggerOnce:!0})})}})(jQuery);    jQuery(document).ready(function($) {
    $('.counter').counterUp({
        delay: 10,
        time: 1000
    });
});
We hope you would like this Counter Up Animation On Scroll using HTML, CSS & JavaScript.

Thank you for reading our blog. If you face any problem in creating this Counter Up Animation On Scroll using HTML, CSS & JavaScript, then contact us or comment us. We’ll try to provide a solution to your problem as soon as possible.

Thank you
Learning robo team

إرسال تعليق

Thank you
Learning robo team

Post a Comment (0)

أحدث أقدم
Learning Robo says...
code copied
Welcome