javascript - Infinite Scroll + Masonry -
trying infinite scroll work masonry. bare me, javascript not main skill.
+function ($) { var $container = $('.masonry'); $container.imagesloaded(function(){ $container.masonry({ columnwidth: '.grid-sizer', gutter: '.gutter-sizer', itemselector: '.item' }) }); $container.infinitescroll({ navselector : '#page-nav', // selector paged navigation nextselector : '#page-nav a', // selector next link (to page 2) itemselector : '.item', // selector items you'll retrieve loading: { finishedmsg: 'no more pages load.', img: 'http://i.imgur.com/6rmhx.gif' } }, // trigger masonry callback function( newelements ) { // hide new items while loading var $newelems = $( newelements ).css({ opacity: 0 }); // ensure images load before adding masonry layout $newelems.imagesloaded(function(){ // show elems they're ready $newelems.animate({ opacity: 1 }); $container.masonry( 'appended', $newelems, true ); }); } ); }(jquery);
it seems if remove imagesloaded function , call masonry, shows images how masonry intended, doesn't infinitely scroll.
as error:
uncaught typeerror: undefined not function
i using foundation , calling scripts in order:
@import 'vendor/masonry.pkgd.js'; @import 'vendor/jquery.infinitescroll.min.js'; @import 'scripts.js';
scripts included code have highlighted @ start. jquery version 2.0.3
you have add imagesloaded
library.
try code
<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> (function() { // main content container var $container = $('.masonry'); // masonry + imagesloaded $container.imagesloaded(function(){ $container.masonry({ // selector entry content columnwidth: '.grid-sizer', gutter: '.gutter-sizer', itemselector: '.item' }); }); // infinite scroll $container.infinitescroll({ // selector paged navigation (it hidden) navselector : "#page-nav", // selector next link (to page 2) nextselector : "#page-nav a", // selector items you'll retrieve itemselector : ".item", // finished message loading: { finishedmsg: 'no more pages load.', img: 'http://i.imgur.com/6rmhx.gif' } }, // trigger masonry callback function( newelements ) { // hide new items while loading var $newelems = $( newelements ).css({ opacity: 0 }); // ensure images load before adding masonry layout $newelems.imagesloaded(function(){ // show elems they're ready $newelems.animate({ opacity: 1 }); $container.masonry( 'appended', $newelems, true ); }); }); /** * optional! * load new pages clicking link */ // pause infinite scroll $(window).unbind('.infscr'); // resume infinite scroll $('.#page-nav a').click(function(){ $container.infinitescroll('retrieve'); return false; }); })();
Comments
Post a Comment