简体   繁体   English

在HTML5应用中加载屏幕

[英]Loading screen in an HTML5 app

I'm working on a project (not a game) that involves getting a number of big assets (css, js, etc). 我正在从事一个涉及获得大量大型资产(css,js等)的项目(而非游戏)。 When opening the page in an UIWebView (iOS) there is an empty white page for 3-5 seconds while everything gets loaded. 在UIWebView(iOS)中打开页面时,在加载所有内容时会出现3-5秒的空白页面。

I'd like to avoid that. 我想避免这种情况。 I'm guessing I should add an HTML5 loading screen but I have no idea how to do that. 我猜我应该添加一个HTML5加载屏幕,但是我不知道该怎么做。 Any pointers? 有指针吗?

I would make the content hidden until it is loaded and use JS to show a loading animation in the meantime. 在将内容加载之前,我会将其隐藏起来,同时使用JS来显示加载动画。

For a simple animation checkout Simple loading animation in HTML5 canvas 简单的动画签出在HTML5 canvas中简单地加载动画

You can use <progress> element in HTML5. 您可以在HTML5中使用<progress>元素。 See this page for source code and live demo. 请参阅此页面以获取源代码和实时演示。 http://purpledesign.in/blog/super-cool-loading-bar-html5/ http://purpledesign.in/blog/super-cool-loading-bar-html5/

here is the progress element... 这是进度元素...

<progress id="progressbar" value="20" max="100"></progress>

this will have the loading value starting from 20. Of course only the element wont suffice. 这将具有从20开始的加载值。当然,仅元素不会满足要求。 You need to move it as the script loads. 您需要在脚本加载时移动它。 For that we need JQuery. 为此,我们需要JQuery。 Here is a simple JQuery script that starts the progress from 0 to 100 and does something in defined time slot. 这是一个简单的JQuery脚本,该脚本从0到100开始进度,并在定义的时隙内执行某些操作。

<script>
        $(document).ready(function() {
         if(!Modernizr.meter){
         alert('Sorry your brower does not support HTML5 progress bar');
         } else {
         var progressbar = $('#progressbar'),
         max = progressbar.attr('max'),
         time = (1000/max)*10, 
         value = progressbar.val();
        var loading = function() {
        value += 1;
        addValue = progressbar.val(value);
        $('.progress-value').html(value + '%');
        if (value == max) {
        clearInterval(animate);
        //Do Something
 }
if (value == 16) {
//Do something 
}
if (value == 38) {
//Do something
}
if (value == 55) {
//Do something 
}
if (value == 72) {
//Do something 
}
if (value == 1) {
//Do something 
}
if (value == 86) {
//Do something 
    }

};
var animate = setInterval(function() {
loading();
}, time);
};
});
</script>

Add this to your HTML file. 将此添加到您的HTML文件。

<div class="demo-wrapper html5-progress-bar">
<div class="progress-bar-wrapper">
 <progress id="progressbar" value="0" max="100"></progress>
 <span class="progress-value">0%</span>
</div>
 </div>

Hope this will give you a start. 希望这会给您一个开始。

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

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