最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to show progress bar until the page completely loads in HTML5CSS3? - Stack Overflow

programmeradmin0浏览0评论

I want a Flash website for loading my html5/css3 webpage.

The page should only appear when it is completely rendered. Before it is displayed, a loading bar must appear.

How should I do that? Do I need something else apart from HTML5 and CSS3?

Please provide me with the tutorial.

I want a Flash website for loading my html5/css3 webpage.

The page should only appear when it is completely rendered. Before it is displayed, a loading bar must appear.

How should I do that? Do I need something else apart from HTML5 and CSS3?

Please provide me with the tutorial.

Share Improve this question edited Jan 22, 2014 at 9:21 Metalskin 4,2687 gold badges40 silver badges63 bronze badges asked Jan 22, 2014 at 9:04 Nikhil TamhankarNikhil Tamhankar 4395 gold badges12 silver badges32 bronze badges 2
  • 6 No, Stack Overflow is not a code/tutorial request site. Use Google – Andy Holmes Commented Jan 22, 2014 at 9:05
  • 10 Com'on! Google sends you to Codeplex or StackOverflow! And why not help, if you have an Answer? Do you want to keep all your knowledge for yourself? Share It! It can make you happy! – CodeHacker Commented Sep 10, 2014 at 17:02
Add a comment  | 

5 Answers 5

Reset to default 10

Put a div at the beginning of your page (well this is a spinner and not a loading bar... but...)

    <div id="work-in-progress">
        <div class="work-spinner"></div>
    </div>

then using JQuery bind to the load event... which gets fired when the page is loaded

  $(window).bind("load", function () {
        $('#work-in-progress').fadeOut(100);
    });

and add some css to the div to

#work-in-progress {
  position: fixed;
  width: 100%;
  height: 100%;
  font-size: 150px;
  text-align: center;
  vertical-align: middle;
  color: #000000;
  z-index: 200000;
  background-color: #FFFFFF;
}

.work-spinner {
  background-color: rgba(0,0,0,0);
  border: 9px solid rgba(27,61,226,0.9);
  opacity: .9;
  border-left: 5px solid rgba(0,0,0,0);
  border-radius: 120px;
  -webkit-box-shadow: 0 0 35px #1B3DE2;
  box-shadow: 0 0 35px #1B3DE2;
  width: 100px;
  height: 100px;
  margin: 0 auto;
  -moz-animation: spin .5s infinite linear;
  -webkit-animation: spin .5s infinite linear;
  -o-animation: spin .5s infinite linear;
  animation: spin .5s infinite linear;
}

@-moz-keyframes spin {
 from {
     -moz-transform: rotate(0deg);
 }
 to {
     -moz-transform: rotate(360deg);
 }
}

@-webkit-keyframes spin {
 from {
     -webkit-transform: rotate(0deg);
 }
 to {
     -webkit-transform: rotate(360deg);
 }
}

@keyframes spin {
 from {
     transform: rotate(0deg);
 }
 to {
     transform: rotate(360deg);
 }
}
@-o-keyframes spin {
 from {
     transform: rotate(0deg);
 }
 to {
     transform: rotate(360deg);
 }
}

pimboden's answer is great, but it needs the actual keyframes to animate.

Here's the missing CSS:

@-moz-keyframes spin {
     from {
         -moz-transform: rotate(0deg);
     }
     to {
         -moz-transform: rotate(360deg);
     }
 }

 @-webkit-keyframes spin {
     from {
         -webkit-transform: rotate(0deg);
     }
     to {
         -webkit-transform: rotate(360deg);
     }
 }

 @keyframes spin {
     from {
         transform: rotate(0deg);
     }
     to {
         transform: rotate(360deg);
     }
 }
 @-o-keyframes spin {
     from {
         transform: rotate(0deg);
     }
     to {
         transform: rotate(360deg);
     }
 }

If you are using huge number of images and just want your users to wait until they get loaded instead of showing slowly revealing images you can use

https://github.com/alexanderdickson/waitForImages

Its pretty much all you may want because rest of the page is just text [if its normal size web page]. It will get loaded in no time.

That's a big question but I can push you in a direction:

$(window).load(function(){  
//initialize after images are loaded  
});  

Sometimes you want to manipulate/render pictures or webpages. For example you want to verticaly and horizontaly align a picture and you need to get the width and height of the picture in order to do that. With $(document).ready() you won’t be able to do that if the visitor doesn’t have the image already loaded, in which case you need to initialize the jquery alignment function when the image finishes loading.

Here may be a step in the right direction:

http://www.gayadesign.com/diy/queryloader-preload-your-website-in-style/

This only shows the website when everything is loaded!

发布评论

评论列表(0)

  1. 暂无评论