- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Load on bottom of div problem (jQuery/JS)
So I have a stream that will load new content when you scroll to the bottom of the div, and then updates a variable that decides how old the content that is being loaded is.
The problem is that sometimes it takes so long to load that it triggers the function again (since it’s still on the bottom I guess). So I guess there is a better way of doing this. This is my code so far:
var ldid = 10;
jQuery(
function($)
{
$('#allpostcontainer').bind('scroll', function()
{
if($(this).scrollTop() +
$(this).innerHeight()
>= $(this)[0].scrollHeight)
{
$("#allpostcontainer").append($("<div>").load("/streampage.php?id=" + ldid, function(){
ldid = ldid + 10;
}));
}
})
}
);
Create a flag like var loading = false;
in the outer scope and wrap the append
and load
with an if
conditional. It should work like this.
var loading = false;
...
...
if(!loading) {
loading = true;
$("#allpostcontainer").append($("<div>").load("/streampage.php?id=" + ldid, function(){
ldid = ldid + 10;
loading = false;
}));
}
Haha good, spent a while trying to get this forum editor to act right! It would be nice to have a preview for this…