Skip to content

Instantly share code, notes, and snippets.

@masotime
Created December 20, 2015 04:21
Show Gist options
  • Save masotime/bed9c57fd492a9cda810 to your computer and use it in GitHub Desktop.
Save masotime/bed9c57fd492a9cda810 to your computer and use it in GitHub Desktop.
Craigslist "infinite scroll"
function track() {
var scrollCount = 0;
var fetching = false;
return function () {
if($(window).height() + $(window).scrollTop() >= $('.content').offset().top + $('.content').outerHeight() && !fetching) {
scrollCount += 100;
fetching = true;
$.ajax('http://sfbay.craigslist.org/search/bka' + ( scrollCount > 0 ? '?s='+scrollCount : '' )).then(function(x) {
console.log('going to append elements');
var $stuff = $(x).find('.content .row');
$('.content .row:last').after($stuff);
fetching = false;
});
}
}
}
$(window).on('scroll', track());
@drewkiimon
Copy link

This was an interview question I had for Salesforce a while back and had to look it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment