3

We have a jQuery Progress Bar. Is there a way we can have the progress bar displaying the loading of an HTML page which has PHP, CSS & JavaScript and all in it?

Like a preloader and when the page has been downloaded and rendered fully then display it.

If not with progress bar can we make a preloader with jQuery?

Starx
  • 77,474
  • 47
  • 185
  • 261
Moon
  • 19,518
  • 56
  • 138
  • 200

3 Answers3

3

look what i found

jQuery Preloader and here is the demo

Moon
  • 19,518
  • 56
  • 138
  • 200
  • it's nice one... but I believe this is focused mainly on preloading images... not sure about the scripts and css – Starx Aug 30 '10 at 14:54
2

Once.. I tried to create this, but It was not pretty. I listed all the things I need to have on a page and increased the progress bar One by one as it was loaded. It was very tremendously long chain. Here is a sample of what I did.

$.getScript('js/lib/ui.js',function() { //Load the Jquery UI
    //Call back function after the loading is complete

    $("#progressinfo").html("Loading Widgets ..."); //Give the information 

    $.getScript('js/lib/widget.js',function() { // Load the jquery ui Widget
    //Call back function after the loading is complete

        $("#progressinfo").html("Loading Widgets: Progress Bar ..."); // Inform

        $.getScript('js/lib/widgets/progressbar.js',function() { // Finally load the Jquery UI progressbar
            //Call back function after the loading is complete

            $("#progressbar").progressbar({ value: 5 }); // change the value of the UI informing the total amount of loadding completion                                             
            $("#progressinfo").html("Loading Widgets: some script ..."); //Inform of another script

            $.getScript('somescript.js',function() { // Load another script
            //Call back function after the loading is complete

               $("#progressbar").progressbar({ value: 6 }); // change the value of the UI informing the total amount of loadding

            });
        });
    });    
});
Starx
  • 77,474
  • 47
  • 185
  • 261
  • can you show me a live demo of this on jsfiddler.com... actually i am new to jQuery so its a little difficult for me to under stand seperated code chunks – Moon Aug 29 '10 at 17:05
  • I am not sure.. If I can create a demo of this in jsfidder.com, but I will update my answer with as much explanatiton as possible – Starx Aug 30 '10 at 02:40
2

Easiest and still sexy way:

hide all the content until the DOM is ready, except for the loading icon which is centered in the page. Then when the content loads, remove the loading icon:

something like this:

                jQuery(function( $ ){
                        function preLoad() {
                            $("#content").addClass("hidden");
                        }

                        function loaded() {
                            $("#content").removeClass("hidden");
                            $('div#preLoader').css({display:'none'}).remove();
                        }

                        preLoad();
                        window.onload=loaded;
                });

EDIT: You'll need an ajax loader gif to place as the background image of #preLoader

HandiworkNYC.com
  • 10,914
  • 25
  • 92
  • 154