Skip to content

Instantly share code, notes, and snippets.

@amarnus
Created June 7, 2011 01:55
Show Gist options
  • Save amarnus/1011531 to your computer and use it in GitHub Desktop.
Save amarnus/1011531 to your computer and use it in GitHub Desktop.
Add Infinite Scroll to Tumblr's Stationary theme
(function($) {
function bindScroll() {
$(window).scroll(function(){
var threshold = 0.8 * ($(document).height() - $(window).height());
if ($(window).scrollTop() >= threshold){
$(window).unbind('scroll');
getNextPage();
}
});
}
function getNextPage() {
this.currentPage = this.currentPage ? ++this.currentPage : 2;
$.ajax({
url: '/page/' + this.currentPage,
type: 'GET',
dataType: 'html',
success: function(data, status, xhr) {
var output = "", query = "?";
$($(data)).find('article').each(function(index, article) {
output += $('<div>').append($(article).clone()).remove().html();
});
$('#stat-articles').append(output);
bindScroll();
}
});
}
$('#stat-navigation').hide();
var allowedUrls = [
'http://blog.amarnus.me',
'http://blog.amarnus.me/',
'http://blog.amarnus.me/page/1'
];
for (var index in allowedUrls) {
if (window.location.href == allowedUrls[index]) {
bindScroll();
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment