I am have a single page Wordpress website using Jetpack Infinite scroll to load one post at a time. I am trying to get Magnific Popup to work after the ajax from the infinite scroll loads the posts after the first call.
I assume the best way to do this is to reinitialise the Magnific Popup so it can work after the ajax, success, perhaps with a callback somehow?
I have not had luck doing this yet even though there are quite a lot of posts online with the same problem, like this question (infinite Scroll with Magnific Popup callback), although I am unsure how to integrate this solution with Infinite Scroll from Jetpack.
Here is my call for the Magnific Popup call. Is there a way to run this again once the ajax loads the next post?
$('.projectDocumentation').each(function() {
$(this).magnificPopup({
delegate: '.popPop',
type: 'image',
image: {
titleSrc: 'caption',
cursor: 'null',
verticalFit: true,
},
gallery: {
enabled:true,
preload: [0,2],
navigateByImgClick: true,
arrowMarkup: '<button type="button" class="mfp-arrow mfp-arrow-%dir%"></button>',
tCounter: '<span class="mfp-counter-index">%curr%/%total%</span>'
},
disableOn: function() {
if( $(window).width() < 600 ) {
return false;
}
return true;
}
});
})
REVISED CODE BELOW
$('#contentContainer').on("click", ".popPop", function(e) { e.preventDefault(); $(this).magnificPopup({ type: 'image', image: { titleSrc: 'caption', cursor: 'null', verticalFit: true, }, gallery: { enabled:true, preload: [0,2], navigateByImgClick: true, arrowMarkup: '<button type="button" class="mfp-arrow mfp-arrow-%dir%"></button>', tCounter: '<span class="mfp-counter-index">%curr%/%total%</span>' }, }).magnificPopup('open'); })