Created
May 12, 2011 15:17
-
-
Save meddulla/968714 to your computer and use it in GitHub Desktop.
simple infinite scrolling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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