How to detect my document has reached the page bottom on mobile devices?

462 Views Asked by At

How can I detect my document has reached the page bottom on mobile devices?

I have this code works perfectly on desktop devices, but not on mobile devices, such as android phones,

$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});

any idea what else should I include in the code to make it work on mobile?

1

There are 1 best solutions below

2
On

I am using it for infinite scroll. I have a "load more" link on nearly bottom of page.

jQuery( window ).scroll( function() {
    var loadMoreLink = 'a.infinite-link';   
    var actualLink = jQuery( loadMoreLink );

    if ( actualLink.length ) {
        var currentPosition = jQuery( loadMoreLink ).offset();
        var pixelsVisible = window.innerHeight - currentPosition.top + jQuery( window ).scrollTop();

        if ( pixelsVisible > 100 ) {
            // time to do some ajax call.
        }            
    }
});