Hi,
Currently, I use the following logic to auto-load new posts from the database when the user reaches the bottom of the site:
$(window).scroll(function() {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
last_msg_funtion();
}
});
Fair enough. It does what it's supposed to do, but I'd like to change this so it starts loading new posts when the user is e.g. 100 pixels from the bottom of the site. Any ideas? When I've tried changing the code, I've either:
** entered an almost endless loop of last_msg_function() calls, because the if() statement matches e.g. from 100 pixels away from the bottom and for every pixel down to 0 pixels when scrolling. So, if you scroll real slow, you'll maybe manage to stop at exactly 100 pixels from the bottom, but that's not going to work in real life.
**) it has to match exactly the pixels from the bottom I define, e.g. 90 pixels. If you stop scrolling at e.g. 89 or 91 pixels, it won't load anything.
So, what should I change to make sure it starts loading when you're 0 -> 100 pixels away from the bottom of the site, but at the same time not send a new request every time to change the scroll position a few pixels in any direction while it's still loading?
Thanks!