search

Home  >  Q&A  >  body text

Number counter animation preloader window when loading Javascript Html CSS

I want to create a number counter animation on my portfolio website. I have some jquery code in my old website that transitions from the preloader to the website when fully loaded.

<script>
  $(window).on('load', () => {
    $('#preloader').fadeOut(1800, function() {
      $(this).remove();
    });
  });
    </script>

How to add number counter animation and add side to upward transition? Thanks

P粉523625080P粉523625080447 days ago646

reply all(1)I'll reply

  • P粉497463473

    P粉4974634732023-09-12 20:01:00

    for you.

    1. Announce count.
    2. Decrease the count value.
    3. Delete the counter span based on the counter value slideUp of your div and .

    Example:

    $(window).on('load', () => {
      let count = 3;
      function ShowCounter() {
        if (count > 0) {
          $("#spnNumber").fadeOut('slow', function() {
            $("#spnNumber").text(count);
            $("#spnNumber").fadeIn();
            count--;
          });
    
        } else if (count == 0) {
          $("#preloader").slideUp();
          $("#spnNumber").remove();
          clearInterval(interval);
    
        }
    
      }
      var interval = setInterval(function() {
        ShowCounter()
      }, 1000)
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <div id='preloader'>Loading ... </div>
    <span id='spnNumber'><span>

    reply
    0
  • Cancelreply