简体   繁体   English

如何在HTML5 / CSS3中完全加载页面之前显示进度条?

[英]How to show progress bar until the page completely loads in HTML5/CSS3?

I want a Flash website for loading my html5/css3 webpage. 我想要一个Flash网站来加载我的html5 / css3网页。

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? 除了HTML5和CSS3,我还需要其他东西吗?

Please provide me with the tutorial. 请给我提供教程。

Put a div at the beginning of your page (well this is a spinner and not a loading bar... but...) 在页面的开头放一个div(这是一个微调器,而不是一个加载栏......但......)

    <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 然后使用JQuery绑定到load事件......在加载页面时会触发它

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

and add some css to the div to 并添加一些CSS到div

#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. pimboden的答案很棒,但它需要实际的关键帧来制作动画。

Here's the missing CSS: 这是缺少的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 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. 使用$(document).ready()如果​​访问者没有已加载图像,您将无法执行此操作,在这种情况下,您需要在图像完成加载时初始化jquery对齐函数。

Here may be a step in the right direction: 这可能是朝着正确方向迈出的一步:

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

This only shows the website when everything is loaded! 这只会在加载所有内容时显示网站!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM