Skip to content

Instantly share code, notes, and snippets.

@faisalhmohd
Last active June 3, 2016 08:49
Show Gist options
  • Save faisalhmohd/ced38e98655148738c2efa563fb2a831 to your computer and use it in GitHub Desktop.
Save faisalhmohd/ced38e98655148738c2efa563fb2a831 to your computer and use it in GitHub Desktop.
Displaying N posts and load more button
var postSize = $(".posts div").size();
var postLimit = 8;
var postDisplay = 8;
var endPosts = false;
$('.posts div:lt('+postDisplay+')').show();
$('#loadmore').click(function () {
if (postDisplay + postLimit <= postSize) {
postDisplay += postLimit;
}
else {
postDisplay = postSize;
endPosts = true;
}
$('.posts div:lt('+postDisplay+')').show();
if (endPosts) {
$('#loadmore').hide();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment