Skip to content

Instantly share code, notes, and snippets.

@meddulla
Created May 12, 2011 15:17
Show Gist options
  • Save meddulla/968714 to your computer and use it in GitHub Desktop.
Save meddulla/968714 to your computer and use it in GitHub Desktop.
simple infinite scrolling
//detect when user has scrolled to end of content
//that is to be loaded using an infinite scroll pattern
//no need for plugin
$(window).scroll(function(){
var bottomList = $("#item_at_bottom_of_list");
var viewTop = $( window ).scrollTop();
var viewBottom = (viewTop + $( window ).height());
var absoluteBottomList = Math.floor(bottomList.offset().top + bottomList.height());
var scrollBuffer = 150;
if ((absoluteBottomList - scrollBuffer) <= viewBottom){
if (data.hasMoreResults && !data.isLoading) {
data.isLoading = true;
//if so, get current month paged data
data.pageNr = data.pageNr + 1;
Model.get(data.year, data.month, data.pageNr);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment