I found this nice jQuery preloader/progress bar, but I cannot get it to work as it is supposed to. The problem is that it first loads my page and after my whole page is loaded the 0%-100% bar displays quickly, after that it reloads my page again. So it does not show the progress bar BEFORE the page loads and it loads the page a second time as well.
Here is my implementation code:
<head>
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery.queryloader2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("body").queryLoader2();
});
</script>
</head>
<body>
My content...No other reference in here for the Jquery preloader
</body>
Thanks for any help in advance.
I could be very, very wrong here, but in my opinion:
I have created a test fiddle and found out the following:
completeImageLoading();is never called because it is only bound to the image elements. When there are no images -> there’s no binding -> no triggering -> nothing completes -> you stay with overlay 0% as demonstrated by the fiddle that is NOT RUN (jsfiddle doesn’t see relative images when the page is not run).<img src="http://example.com/image.jpg">– then it won’t work because the plugin doesn’t recognize them. In fact it is using$.ajaxto load images which, obviously, generates a error when trying to access another domain.Suggestions:
Edit regarding preloader
Regarding preloader… if displaying progress is not mandatory for you, then you can just use a
window.onloadtrick. On DOM ready$(...)you create an opaque page overlay with a “Please wait…” message and some animation if you fancy it. Then you wait for window.onload event which “fires at the end of the document loading process… when all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading.” Whenwindow.onloadtriggers, you just remove your overlay and voila – the page is ready!Edit 2 regarding preloader
Actually, you don’t even need
$(...)… what the hell was I thinking? Just create your overlay (a simple div with a unique id) in your html, style it so that it fills the screen and give it az-index:1337CSS attribute so that it covers the entire page. Then, on window.onload:Of course, it’s not really a preloader, but simply an imitation.
Here’s a working fiddle you can play with.
P.S. I personally don’t appreciate preloaders, but that’s just me…