Skip to content

Instantly share code, notes, and snippets.

@nicklasos
Last active January 4, 2016 02:49
Show Gist options
  • Save nicklasos/8558163 to your computer and use it in GitHub Desktop.
Save nicklasos/8558163 to your computer and use it in GitHub Desktop.
Simple endless scroll
var page = {
scrollAvailable: true,
currentPage: 0,
init: function() {
var _this = this;
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height() /* - 10 */) {
_this.scroll();
}
});
},
scroll: function() {
var _this = this;
if (this.scrollIAvailable) {
$('#scroll').show();
this.scrollAvailable = false;
this.currentPage += 1;
$.get('page/' + this.currentPage, function(response) {
if (response.status != 'last-page') {
_this.scrollAvailable = true;
}
$('#content').append(response.content);
$('#scroll').hide();
});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment