The following code is used to detect if a user has scrolled to the bottom of the page and it works.
if($(window).scrollTop() == $(document).height() - $(window).height()){
//do something
}
Problem:
I don't understand why you subtract the height of the window from the height of the document, then compare that to the scroll height to determine whether or not the bottom of the page has been reached. Why isn't it simply
if($(window).scrollTop() == $(document).height()){
//do something
}
or
if($(window).scrollTop() == $(window).height()){
//do something
}