MB.
MB.

Reputation: 4211

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). When opening the page in an UIWebView (iOS) there is an empty white page for 3-5 seconds while everything gets loaded.

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. Any pointers?

Upvotes: 1

Views: 2895

Answers (2)

Raj Nandan Sharma
Raj Nandan Sharma

Reputation: 3862

You can use <progress> element in HTML5. See this page for source code and live demo. 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. You need to move it as the script loads. For that we need JQuery. Here is a simple JQuery script that starts the progress from 0 to 100 and does something in defined time slot.

<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.

<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.

Upvotes: 0

Tobi
Tobi

Reputation: 2040

I would make the content hidden until it is loaded and use JS to show a loading animation in the meantime.

For a simple animation checkout Simple loading animation in HTML5 canvas

Upvotes: 1

Related Questions