Created
February 8, 2012 00:11
-
-
Save envex/1763280 to your computer and use it in GitHub Desktop.
Infinite Scroll Script
This file contains hidden or 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
/* | |
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