I’m trying to detect when the user scrolls to the bottom of a page using jQuery, and this does it:
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
fetchData();
}
});
But I want to detect when the window reaches 100px before the bottom of the page. So it would be the same as above, but with - 100 at the end like this:
if ($(window).scrollTop() == $(document).height() - $(window).height() - 100) {...}
Yet this doesn’t work, at all. I’ve tested the code elsewhere and it returns a valid value, so what gives? Anyone know?