View Full Version : Hide a loading div if not new content available to load

03-18-2012, 04:58 PM

I have been everywhere still trying to find a solution of this,

I have the following code which loads a new html page into the bottom of my document when the user reaches the bottom of the page.

alreadyloading = false;
nextpage = 2;

$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
if (alreadyloading == false) {
var url = "page"+nextpage+".html";
alreadyloading = true;
$.post(url, function(data) {
alreadyloading = false;

#Loading is a div which contains a loading jpeg which is fixed to the bottom of the screen. This div appears when the user hits the bottom of the screen, and then disappears once the content has fully loaded.

The problem I have is that once the user has loaded all the content that is available. Say I have 'page2.html, page3.html, page4.html' to load one at a time as the user hits the bottom of the screen. I need the loading bar to stay hidden when it tries to load the 'page5' which does not yet exist...

Is this easy to do to alter my javascript code?

I am at a loss with this. Any help would be appreciated. I asked a similar question before but have adapted the code now for the loading bar, just need this little glitch to be fixed.

Thank you!

Website at:


so you can see that I mean. (note that the graphics on the website are made by me but are not my work, just for placement)

03-18-2012, 07:25 PM
$('element').length == 0; means no element found
if ($('element').length) { means the element was found

Use either line to show/not show your loading image

03-18-2012, 08:04 PM
$('element').length == 0;

^^ isn't this to say whether it is currently available on the page?
I could be wrong. Can it be used to search the index folder of the website, to try to find the next 'page#.html' '# meaning number'

Just like "var url = "page"+nextpage+".html";" does?

Thanks for the reply though!

03-18-2012, 11:35 PM
Solved by using ajax instead. was able to use the error and complete function to do what i wanted! Thanks for your help