javascript - infinite scroll fires before the bottom -


hello using following line of code fire appending of item 100px before user @ bottom:

var height = window.innerheight; if ($(window).scrolltop() + height + 100 >= $(document).height()) 

the problem many times there multiple append commands sent. if user reaches 100px before bottom command executed. command executed again , again user keeps scrolling , down.

i have tried this:

$(window).scroll(function () {     if ($(window).scrolltop() + height == $(document).height()) {         //     } } 

scroll events fire in browsers. guess it's firing multiple times before first request returns. want add flag prevent requests if there 1 in flight.

var requesting = false;  function renderpage() { /* ... */ }  function makerequest() {   if (!requesting) {     // go ahead , fetch next page.     requesting = true;     $.ajax(...).then(renderpage).always(function() {       requesting = false;     });   } }  $(window).on('scroll', function() {   if (/* scrolled 100px above bottom */) {     makerequest();   } }); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -