Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a page loader using jQuery

I need a little help. I do not know where to start. I need to add a page loader to my website. I first submit a form it then uses SimpleXML to call an exterior XML Sheet with expedia... It takes a minute to load, so I would like to add the image loader to this page. But how do I go about doing this? I have looked on Google and could not find any useful info.

I need it to show the loader until the COMPLETE page has loaded.

like image 519
luv2code Avatar asked Nov 28 '22 09:11

luv2code


1 Answers

This has many solutions, but a simple one is to:

1- Create an overlay DIV with your loader stuff and prepend to BODY;
2- Add an event listener for window.load or document.ready event that hides this DIV.

// On the first line inside BODY tag
<script type="text/javascript">
    jQuery("body").prepend('<div id="preloader">Loading...</div>');
    jQuery(document).ready(function() {
        jQuery("#preloader").remove();
    });
</script>

(code typos fixed)

like image 68
Ricardo Souza Avatar answered Dec 10 '22 21:12

Ricardo Souza