infinite Scroll with Magnific Popup callback

笑着哭i 提交于 2019-12-10 13:37:15

问题


I'm using Infinite scroll and Magnific Popup.

The popup works on the content which is 'page 1' but fails after that. I've attempted to use a callback for MagnificPopup within the infiniteScroll call.

$grid.infiniteScroll({
path: '.pagination__next',
append: '.grid__item',
outlayer: msnry,
status: '.page-load-status',
}, function( newElements ) {
  $('.open-pop').magnificPopup({
  type: 'inline',
  mainClass: 'mfp-fade',
  fixedContentPos: false,
   gallery: {
   enabled: true,
   navigateByImgClick: false,
   }
 });

 });

My question is similar to this Magnific popup and infinite scrolling, which I've unsuccessfully tried to implement.

Potentially an added complication is I'm using Masonry. This is my full code:

// init Masonry

var $grid = $('.grid').masonry({
 itemSelector: 'none', // select none at first
 columnWidth: '.grid__col-sizer',
 gutter: 26,
 percentPosition: true,
 stagger: 30,
 // nicer reveal transition
 visibleStyle: { transform: 'translateY(0)', opacity: 1 },
 hiddenStyle: { transform: 'translateY(100px)', opacity: 0 },
});

// get Masonry instance
var msnry = $grid.data('masonry');

// initial items reveal
$grid.imagesLoaded( function() {
$grid.removeClass('are-images-unloaded');
$grid.masonry( 'option', { itemSelector: '.grid__item' });
var $items = $grid.find('.grid__item');
$grid.masonry( 'appended', $items );
});

$grid.infiniteScroll({
path: '.pagination__next',
append: '.grid__item',
outlayer: msnry,
status: '.page-load-status',
}, function( newElements ) {
 $('.open-pop').magnificPopup({
 type: 'inline',
 mainClass: 'mfp-fade',
 fixedContentPos: false,
 gallery: {
  enabled: true,
  navigateByImgClick: false,
 }
});

});

回答1:


Use onInit event for callback function.

onInit: function() { this.on( 'append', function() {...}) }


来源:https://stackoverflow.com/questions/46348603/infinite-scroll-with-magnific-popup-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!