Search code examples
javascriptjquery

scroll event not working on mobile


Setch.me loading normally on desktop but not trigerring on mobile unless if I click on photographers/makeup artists, I've added height=device-height after searching for a solution here but that didn't work.

$(window).scroll(function() { 
    if($(window).scrollTop() + $(window).height() >= $(document).height()) { 
        track_page++; 
        load_contents(track_page); 
    }

Solution

  • Try this:

    $(document.body).on('touchmove', onScroll); // for mobile
    $(window).on('scroll', onScroll); 
    
    // callback
    function onScroll(){ 
        if( $(window).scrollTop() + window.innerHeight >= document.body.scrollHeight ) { 
            track_page++; 
            load_contents(track_page); 
        }
    }