I have a problem on my site with using Infinite Scroll and Fancybox at the same time. Everything works fine on the initially loaded images .. then as soon as new content is pulled via Infinite scroll, the new images don't open with Fancybox anymore... So far it makes sense, the original Fancybox call never "saw" the new elements.
So I need to put Fancybox through the Infinite Scroll callback. Or at least this is what I have come up after reading on here and Google.
However, my code does now apply Fancybox to the newly loaded images, but the Fancybox Overlay shows Error: The requested content cannot be loaded. Please try again later.
Can't seem to figure out what the problem is, help much appreciated!!
Oh yes I should also mention I am also using isotope and everything runs on Wordpress. I also found this: Using EasyFancybox Wordpress Plugin alongside Infinite-Scroll but have not yet managed to get it to work for me correctly...
What I have come up with so far:
// ISOTOPE
$(window).load(function(){
var $container = $('#portfolio-centre-wrap')
// initialize Isotope
$container.isotope({
// options...
resizable: false, // disable normal resizing
// set columnWidth to a percentage of container width
itemSelector : '.portfolio-item',
masonry: { columnWidth: $container.width() / 3 }
});
$container.infinitescroll({
navSelector : '#pagination', // selector for the paged navigation
nextSelector : '#pagination .next a', // selector for the NEXT link (to page 2)
itemSelector : '.portfolio-item', // selector for all items you'll retrieve
loading: {
finishedMsg: 'Sorry, that is it for now...',
img: 'http://dev.deborre.net/wp-content/themes/deborre2012v2/_img/loading.gif',
msgText: ''
}
},
// call Isotope as a callback
function(newElements) {
var $newElems = $(newElements);
$newElems.imagesLoaded(function(){
$container.isotope('appended', $newElems );
//fancybox
var thumbnails = jQuery("a:has(img)").not(".nolightbox").filter( function() { return /\.(jpe?g|png|gif|bmp)$/i.test(jQuery(this).attr('href')) });
thumbnails.addClass("fancybox").attr("rel","fancybox").getTitle();
$(newElements).fancybox({
'cyclic': true,
'autoScale': true,
'padding': 10,
'opacity': true,
'speedIn': 500,
'speedOut': 500,
'changeSpeed': 300,
'overlayShow': true,
'overlayOpacity': "0.8",
'overlayColor': "#585858",
'titleShow': false,
'titlePosition': 'inside',
'enableEscapeButton': true,
'showCloseButton': true,
'showNavArrows': true,
'hideOnOverlayClick': true,
'hideOnContentClick': true,
'width': 560,
'height': 340,
'transitionIn': "fade",
'transitionOut': "fade",
'centerOnScroll': true
});
});
}
);
//ANSWER:
It seems changing:
$(newElements).fancybox({
to:
$(.fancybox).fancybox({
solved the issue for me.