Last active
November 9, 2017 10:46
-
-
Save weartstudio/a9ff1c954737af7cbd92c281b317dda8 to your computer and use it in GitHub Desktop.
JS - Masonry and old infinite scroll
This file contains hidden or 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 $container = $('#container'); | |
$container.imagesLoaded(function(){ | |
$container.masonry({ | |
itemSelector: '.box', | |
columnWidth: 100 | |
}); | |
}); | |
$container.infinitescroll({ | |
navSelector : '#page-nav', // selector for the paged navigation | |
nextSelector : '#page-nav a', // selector for the NEXT link (to page 2) | |
itemSelector : '.box', // selector for all items you'll retrieve | |
loading: { | |
finishedMsg: 'No more pages to load.', | |
img: 'http://i.imgur.com/6RMhx.gif' | |
} | |
}, | |
// 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 ); | |
}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment