Skip to content

Instantly share code, notes, and snippets.

@envex
Created February 8, 2012 00:11
Show Gist options
  • Save envex/1763280 to your computer and use it in GitHub Desktop.
Save envex/1763280 to your computer and use it in GitHub Desktop.
Infinite Scroll Script
/*
Infinite Scroll for the listings
*/
if($('#listings').length){
if($('.alignleft a').length){
$(document).ready(function() {
var $loading = $("<p class='loading'>Loading more listings...</p>"),
$footer = $('#footer_container'),
opts = {
offset: '100%'
};
$('#listings_container').append($loading);
$footer.waypoint(function(event, direction) {
$footer.waypoint('remove');
$('#listings_container').append($loading);
$.get($('.alignleft a').attr('href'), function(data) {
var $data = $(data);
$('#listings').append($data.find('#listings').html());
$('#listings li:odd').addClass('odd');
$loading.detach();
$('.alignleft a').replaceWith($data.find('.alignleft a'));
/*
Have we reached the end my friend?
*/
if(!$data.find('.alignleft a').length){
$loading.detach();
}else{
$footer.waypoint(opts);
}
});
}, opts);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment