I am trying to use the following function to load an ajax call when the user scrolls to the bottom. However, for some reason the function only fires the ajax call when the user scrolls to down and then back to the top. Here is my code:
$(window).scroll(function()
{
if($(window).scrollTop() == $(document).height() - $(window).height())
{
$('div#loadmoreajaxloader').show();
$.ajax({
url: "loadmore.php",
success: function(html)
{
if(html)
{
var el = jQuery(html);
jQuery(".content").append(el).masonry( 'appended', el, true );
$('div#loadmoreajaxloader').hide();
}else
{
$('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
}
}
});
}
});
Check it like this:
EDIT:
I’ve done a JSBin which displays a div when user scrolls to the bottom. You can see it here: http://jsbin.com/axobow/2
I know that’s not exactly what you need, but it should give you an idea. Iv’e also updated the code a little bit to go inline with what you should have as the final product.
Please check.