...

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



jbyrne
03-18-2012, 03:58 PM
Hello,

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) {
$("#loading").slideDown();
var url = "page"+nextpage+".html";
alreadyloading = true;
$.post(url, function(data) {
$('#newcontent').children().last().after(data);
alreadyloading = false;
nextpage++;
$("#loading").slideUp();
});
}
}
});


#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:

www.jb-design.me/marchupdate2/

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)

sunfighter
03-18-2012, 06: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

jbyrne
03-18-2012, 07: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!

jbyrne
03-18-2012, 10: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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum