Created
December 20, 2015 04:21
-
-
Save masotime/bed9c57fd492a9cda810 to your computer and use it in GitHub Desktop.
Craigslist "infinite scroll"
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
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()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was an interview question I had for Salesforce a while back and had to look it up.