Loading screen example

。_饼干妹妹 提交于 2019-12-03 21:26:10
Bikas

Your code works perfectly fine. And for information $(document).ready() is better to use.

The way you've linked your CSS, I assume you're directly opening the HTML file, i.e. by double clicking on the file (correct me if I'm wrong). If this is the case then you've to correct your jQuery linking to:

<script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Two problems with your both scenarios :

Problem 1 : When you apply class="loader" :

Here the problem is that when you use class="loader" your css applies to the div. and in javascript you are using $("#loader") instead of $(".loader")

Problem 2 : When you apply id="loader" :

Here the problem is that you remove the class="loader" and add id="loader" so your css will not be applied to the div.

Solution : Update your div with class as mentioned below :

<div id="divloader" class="loader"></div>

Update your javascript as mentioned below :

<script type="text/javascript">
    $(window).load(function () {

        $("#divloader").fadeOut("slow");

    })
</script>

problem: you are missing a semicolon ; at the end of the function

change to

 $(window).load(function () {

            $("#loader").fadeOut("slow");

        });

and add this too

$(document).ready(function(){
    $("#page1").fadeIn(3000)
});

don't forget to give style="display:none;" for div page1

Hope it helps..!!

Instead of

$(window).load(function () {
 //your code
});

use

$(document).ready(function(){ 
 //your code
});

This gives the fadeIn effect you wish to have:

$(document).ready(function(){
            $('body').css('display', 'none');
            $("body").fadeIn("slow");

});

And here's a Fiddle.

Hope this helps!

Try this:

HTML:

<div id="dvLoading"></div>

CSS:

#dvLoading
{
   background:#000 url(images/loader.gif) no-repeat center center;
   height: 100px;
   width: 100px;
   position: fixed;
   z-index: 1000;
   left: 50%;
   top: 50%;
   margin: -25px 0 0 -25px;
}

SCRIPT:

<script>
$(window).load(function(){
  $('#dvLoading').fadeOut(2000);
});
</script>

Here is a reference and demo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!