javascript - scroll not reaching end of page before loading more users -


i loading information scroll down on page. start scrolling more information being downloaded display. there way scroll reach end of page shows quick message 2 seconds "loading more images" , shows next batch.

 function updatestatus() {  // load more users on scroll $('#main').scroll(function () {     if ($('#main').scrolltop() >= $(document).height() - $('#main').height()) {         $('#status').text('loading more items...');         $('#users').append(next());     }     settimeout('updatestatus();', 1500); }); } 

after suggested answers update

function updatestatus() {         $('#users').append(next());     }      // load more users on scroll     $(document).ready(function(){         $('#main').scroll(function () {             if ($('#main').scrolltop() >= ($(document).height() - $('#main').height())) {                 $('#status').text('loading more items...');             }          });         settimeout(updatestatus, 2500);     }); 

with current edit when scroll bottom of page loads next 20 users reaching end of page again doesn't load more. when take settimeout(updatestatus, 2500) , place within $('#main').scroll... when scroll without little reaching bottom of page data keeps loading , loading before reaching end of page.


next = function () {     var _page = $.views.roster.viewmodel.currentpage() + 1;     $.views.roster.getpage("/api/roster", 9, _page); };  $.views.roster.getpage = function (url, id, pagenumber) {         $.grain.ajax.get({             url: url,             datatosubmit: { pagenumber: pagenumber, id: id },             datatype: "json",             onsuccess: function (data, status, jqxhr) {                 $.views.roster.rosterviewmodel.addusers(data);                 $.views.roster.viewmodel.currentpage(pagenumber);             }         });     }; 

perhaps you're looking this? (untested code)

function updatestatus() {     $('#status').text('');     $('#users').append(next()); }  // load more users on scroll $('#main').scroll(function () {     if ($('#main').scrolltop() >= $(document).height() - $('#main').height()) {         $('#status').text('loading more items...');         settimeout(updatestatus, 1500);     }  }); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -