Forked from gregrickaby/infinite-scroll-masonry-imagesloaded.php
Created
September 16, 2018 14:50
-
-
Save CherenkovS/77c110f5bc8926985665697c9b7827da to your computer and use it in GitHub Desktop.
Infinite Scroll + Masonry + ImagesLoaded
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
/** | |
* Be sure to include library scripts in this order. Can be placed either | |
* in the header or footer. | |
*/ | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-infinitescroll/2.0b2.120519/jquery.infinitescroll.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/masonry/3.1.2/masonry.pkgd.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.0.4/jquery.imagesloaded.min.js"></script> |
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
/** | |
* Infinite Scroll + Masonry + ImagesLoaded | |
*/ | |
(function() { | |
// Main content container | |
var $container = $('#content'); | |
// Masonry + ImagesLoaded | |
$container.imagesLoaded(function(){ | |
$container.masonry({ | |
// selector for entry content | |
itemSelector: '.entry-content', | |
columnWidth: 200 | |
}); | |
}); | |
// Infinite Scroll | |
$container.infinitescroll({ | |
// selector for the paged navigation (it will be hidden) | |
navSelector : ".navigation", | |
// selector for the NEXT link (to page 2) | |
nextSelector : ".nav-previous a", | |
// selector for all items you'll retrieve | |
itemSelector : ".entry-content", | |
// finished message | |
loading: { | |
finishedMsg: 'No more pages to load.' | |
} | |
}, | |
// Trigger Masonry as a callback | |
function( newElements ) { | |
// hide new items while they are loading | |
var $newElems = $( newElements ).css({ opacity: 0 }); | |
// ensure that images load before adding to masonry layout | |
$newElems.imagesLoaded(function(){ | |
// show elems now they're ready | |
$newElems.animate({ opacity: 1 }); | |
$container.masonry( 'appended', $newElems, true ); | |
}); | |
}); | |
/** | |
* OPTIONAL! | |
* Load new pages by clicking a link | |
*/ | |
// Pause Infinite Scroll | |
$(window).unbind('.infscr'); | |
// Resume Infinite Scroll | |
$('.nav-previous a').click(function(){ | |
$container.infinitescroll('retrieve'); | |
return false; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment