Last active
January 4, 2016 02:49
-
-
Save nicklasos/8558163 to your computer and use it in GitHub Desktop.
Simple endless 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
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