How to use page loader jQuery


Hi friends, in this tutorial you will learn how to use the page loader jquery. This is very simple but often required while sending HTTP requests or any kind of request or submitting any form of data to let the user wait for the response till the response comes to the user.

Also, read, Get Value of a Radio Button Using jQuery

Steps to use page loader jQuery

Step 1:- Create an HTML file in the root directory of your local server i.e. www.

Step 2:- Paste the below code in the file.

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>Page Loader!</title>
    <style type="text/css">
      #loader {
          display: none;
          position: fixed;
          top: 0;
          left: 50;
          width: 100%;
          height: 10%;
          background-color: rgba(0, 0, 0, 0);
          z-index: 9999;
        }

    </style>
  </head>
  <body>
    <div class="container" style="width: 50%;">
      
        <div id="loader"><div class="spinner-border text-info"></div> Please wait.........</div><br><br>
        <h1>Page Loader jQuery Example !</h1>
          <div class="mb-3">
            <label for="exampleFormControlInput1" class="form-label">Name</label>
            <input type="text" class="form-control" id="name">
          </div>
          <div class="mb-3">
            <label for="exampleFormControlTextarea1" class="form-label">Phone Number</label>
            <input type="number" class="form-control" id="phone_number">
          </div>
          <button type="button" class="btn btn-primary btn-sm frm_btn">Submit</button>
        </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
  </body>
</html>

Step 3:- Now, add the below javascript code or jquery code inside the script tag before the body tag ends in the above HTML file.

<script type="text/javascript">
      $(document).ready(function(){
          $('.frm_btn').click(function(){

               // Show the loader
              function showLoader() {
                $('#loader').fadeIn('fast');
              }

              // Hide the loader
              function hideLoader() {
                $('#loader').fadeOut('fast');
              }

              showLoader();

              setTimeout(function() {
                hideLoader();
              }, 3000);
          });
      });
    </script>

Explanation of the above jquery code

  • First of all, we will use the click() function or on-click event for the HTML file.
  • When you click the submit button then it will call two functions respectively. One is showLoader() and another is hideLoader().
  • Now, in the showLoader() function, I have called the fadeIn() method with the #loader div. This method makes a hidden element visible that means as soon as you click the submit button it will display the content or any kind of animation that exist in the loader div. Also, you have noticed that I have used a parameter “fast” inside the fadeIn() method to display the loader div content faster.
  • Also, I have used another function called hideLoader(). So, inside this function, I have called another jquery method fadeOut(). This method makes a visible element to a hidden state that means as soon as you click the submit button, it will hide all the content of animation that exist in the loader div.
  • Also, I have used a “fast” parameter to hide the loader div faster but in this case, I have used another method settimeout() for the hideLoader() function. As soon as the hideLoader() function is called the settimeout() method will be called automatically to hide the elements of the loader div based on the milliseconds declared inside the settimeout() method.

For 1 second = 1000 milliseconds.

Complete Code:-

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>Page Loader!</title>
    <style type="text/css">
      #loader {
          display: none;
          position: fixed;
          top: 0;
          left: 50;
          width: 100%;
          height: 10%;
          background-color: rgba(0, 0, 0, 0);
          z-index: 9999;
        }

    </style>
  </head>
  <body>
    <div class="container" style="width: 50%;">
      
        <div id="loader"><div class="spinner-border text-info"></div> Please wait.........</div><br><br>
        <h1>Page Loader jQuery Example !</h1>
          <div class="mb-3">
            <label for="exampleFormControlInput1" class="form-label">Name</label>
            <input type="text" class="form-control" id="name">
          </div>
          <div class="mb-3">
            <label for="exampleFormControlTextarea1" class="form-label">Phone Number</label>
            <input type="number" class="form-control" id="phone_number">
          </div>
          <button type="button" class="btn btn-primary btn-sm frm_btn">Submit</button>
        </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
          $('.frm_btn').click(function(){

               // Show the loader
              function showLoader() {
                $('#loader').fadeIn('fast');
              }

              // Hide the loader
              function hideLoader() {
                $('#loader').fadeOut('fast');
              }

              showLoader();

              setTimeout(function() {
                hideLoader();
              }, 3000);
          });
      });
    </script>
  </body>
</html>

If you access the file from your browser and click on the submit button then you can see the output as shown below.

Conclusion:- I hope this tutorial will help you to understand the concept. If there is any doubt then please leave a comment below.


Leave a Comment

Mahjong Ways 2

CERI188

CERI188

sv388

CERI188

KUPU178 TOTO SLOT

CERI188

CERI188 TOTO Singapore

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

sabung ayam online

THOR311

parlay

RATU311

KUPU178

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

CERI188

CERI188

KUPU178

RATU311: Alternatif karnpuracollege

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

RATU311

RATU311

RATU311

judi bola

live casino

sv388

sv388

sabung ayam online

sabung ayam online

Thor311 Terbaru

CERI188: Taruhan Bola Sbobet

THOR311 DEMO SLOT

THOR311 MAHJONG

RATU311: BONUS SABUNG AYAM

CERI188

parlay

KUPU178

RATU311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

CERI188

CERI188: Masuk Akun Slot Super Cepat

KUPU178: Slot Online Mahjong Bet 200

THOR311 PRO

THOR311

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

THOR311

HOKI311

HOKI311

RATU311

RATU311

KUPU178

THOR311

KUPU178

THOR311

RATU311

HOKI311

KUPU178

KUPU178

RATU311

THOR311 TOTO4D

KUPU178

Live Casino Roullate

RATU311

RATU311

RATU311

RATU311

THOR311

THOR311

THOR311

RATU311

CERI188

DAFTAR KUPU178

LINK DAFTAR CERI188

CERI188

APK KUPU178

KUPU178

CERI188

CERI188

RATU311

KUPU178

THOR311 DOMINO QQ

judi bola online

Mix Parlay

CERI188

CERI188

RATU311

live casino online

RATU311

Mix Parlay

Slot PG Soft

CERI188

RATU311

RATU311

CERI188

THOR311

CERI188

THOR311

Game Thor311

THOR311

HOKI311

live casino

sv388

HOKI311

HOKI311

slot mahjong

Thor311 Alternatif

RATU311

HOKI311

HOKI311

HOKI311

HOKI311

CERI188

THOR311 RESMI

THOR311 AKSES

THOR311

THOR311 RTP

parlay

HOKI311

THOR311

Thor311 Aplikasi

RATU311 NONTON BOLA

CERI188 Link RTP LIVE

THOR311

Thor311 Live Casino

CERI188

akses VIP THOR311

THOR311

link daftar THOR311

THOR311

situs thor311

RATU311

HOKI311 Link SABUNG AYAM RESMI

HOKI311 Link QRIS EWALLET

RATU311

LINK CERI188

parlay

HOKI311 Link RTP Gacor

THOR311

HOKI311 Link Apk Resmi

CERI188

KUPU178 Link Daftar

CERI188

CERI188

CERI188

CERI188

CERI188

HOKI311

RATU311

RATU311

HOKI311 Lapak Arena Slot

RATU311 judi bola

HOKI311 Link Spaceman Online

HOKI311 Link Daftar Resmi

CERI188 Toto SGP Online

KUPU178

HOKI311 TEMBAK IKAN ONLINE

KUPU178

HOKI311 Link Login Alternatif

HOKI311 Live Casino Online

HOKI311 Situs Slot Gacor

THOR311

THOR311

situs judi bola

Ceri188 Game Online

CERI188

link login CERI188

link login CERI188

CERI188

THOR311

HOKI311

HOKI311

CERI188

parlay

THOR311

RATU311

HOKI311

HOKI311

HOKI311

RATU311

THOR311

KUPU178

HOKI311

KUPU178

KUPU178

HOKI311

parlay

slot gacor

kupu178 link alternatif

kupu178 slot

kupu178 daftar

kupu178 login

link daftar kupu178

judi bola

HOKI311

RATU311

link alternatif RATU311

Link daftar RATU311

link login RATU311

RATU311

RATU311

KUPU178

KUPU178

THOR311

KUPU178

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

KUPU178

KUPU178

HOKI311

THOR311

KUPU178

THOR311

THOR311

slot thailand

judi bola

THOR311

THOR311

KUPU178

THOR311

THOR311

slot gacor

slot gacor

yakuza303

unobet77

slot gacor

slot gacor

RATU311

parlay

parlay

slot gacor

parlay

THOR311