Skip to content

Instantly share code, notes, and snippets.

@krishna19
Forked from FutureMedia/load-more-masonry.js
Created August 15, 2016 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishna19/a9db9bacac8415c8eefb9c3adde44eb3 to your computer and use it in GitHub Desktop.
Save krishna19/a9db9bacac8415c8eefb9c3adde44eb3 to your computer and use it in GitHub Desktop.
/*
* Load More for Masonry modification
*
* Full post:
* http://www.billerickson.net/infinite-scroll-in-wordpress/
*
*/
jQuery(function($){
$('.post-listing').append( '<span class="load-more">Click here to load earlier stories</span>' );
var button = $('.post-listing .load-more');
var page = 2;
var loading = false;
$('body').on('click', '.load-more', function(){
if( ! loading ) {
loading = true;
var data = {
action: 'be_ajax_load_more',
nonce: beloadmore.nonce,
page: page,
query: beloadmore.query,
};
$.post(beloadmore.url, data, function(res) {
if( res.success) {
var $items = res.data;
var $grid = $( '.post-listing' );
$grid.append( $items ).each( function() {
$grid.masonry( 'reloadItems' );
});
$grid.masonry( 'layout' );
// $('.grid-item').animate({ opacity: 1 }); // you may need this
page = page + 1;
loading = false;
} else {
// console.log(res);
}
}).fail(function(xhr, textStatus, e) {
// console.log(xhr.responseText);
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment