Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page Loader in html page

I am trying to show a loader GIF image in the div section of this html page. But I can't get it to work. The div content is hidden and the GIF image disappears.

CSS:

.loader {
    background-image: url(image/Preloader_8.gif);
    background-repeat: no-repeat;
    height:100px;
    width:200px;
}

JavaScript:

<script type="text/javascript">
    $(window).load(function() {
        $(".loader").fadeOut("slow");
    })
</script>

Html:

<body>
    <div class="loader">
        Loading Image
    </div>
</body>
like image 674
user3580570 Avatar asked Oct 23 '15 06:10

user3580570


2 Answers

Are you using AJAX to fetch the content in div or simply .load function?

In case of .load() jQuery event,

$( ".loader" ).load( "test.html", function() { 
  $(".loader").fadeOut("slow"); 
});

In case of AJAX request, call the function loader in success event of AJAX call.

function loader() {
    $(".loader").fadeOut("slow");
});
like image 86
Thamilhan Avatar answered Sep 26 '22 20:09

Thamilhan


HTML

    <body>
      <div class="loader" style="display:none">
             Loading Image
      </div>
    </body>

js

$(window).load(function() {
    $(".loader").fadeOut("slow");
})

Please add the following script on the top of your web page

$(".loader").fadeIn();

Add loading div on top of just above script

like image 35
Alok Deshwal Avatar answered Sep 25 '22 20:09

Alok Deshwal