I'm trying to initialize the FitVids plugin on Fancybox modal content once that content is loaded. It works perfectly if I use the onUpdate
callback for when the user resizes the viewport, but if I try to get it working with afterShow
to apply it once the content is shown, I get nothing. I've tested to ensure that afterShow
works by throwing in console.log('whatever')
and that was successful.
This is the code I'm using:
$('.tile-link.fancybox').click(function() {
var url = $(this).data('url');
var getContent = $('.tile-lightbox-content').load(url + ' #lightboxBucketContent');
$('.tile-lightbox-content').empty();
$.fancybox({
content: getContent,
width: '90%',
height: '90%',
type: 'html',
scrolling: 'no',
modal: false,
padding: 20,
enableEscapeButton: true,
titleShow: true,
autoSize: false,
autoResize: true,
autoDimensions: false,
aspectRatio: true,
helpers: {
media: true
},
// afterShow doesn't work
afterShow: function() {
$('.fancybox-inner').fitVids({
customSelector: 'iframe[src^="http://somewebsite.com"]'
});
},
// onUpdate works correctly
onUpdate: function() {
$('.fancybox-inner').fitVids({
customSelector: 'iframe[src^="http://somewebsite.com"]'
});
}
});
});
I'm using this on a WordPress website where content is loaded into some masonry tiles that trigger a fancybox modal window when clicked and load a portion of a page via the jQuery load
function. Everything works dandy with the exception of the FitVids. The tile modal content often contains iframe video embeds and I need them to cooperate on touch/mobile devices.
Thanks in advance.