Now I wrote a standart code for loading iframe in window FancyBox. So I specified type iframe
and href
link with youtube params.
$.fancybox({
'type' : 'iframe',
'maxWidth': "90%",
'href' : href.replace(new RegExp('watch\\?v=', 'i'), 'embed/') + '?theme=dark&color=white&autohide=1&rel=0&iv_load_policy=3&modestbranding=1&enablejsapi=1&showinfo=0&autoplay=1',
'padding' : 0,
'margin' : 0,
'autoCenter': false,
'scrolling' : 'no',
'fitToView' : false,
'width' : 950,
'overlayShow': true,
beforeLoad : function() {
var template;
var hash;
var info;
getVideo(id);
},
afterLoad:function(){
$('.fancybox-inner').append(template);
changeURL(matchYoutubeUrl(href)+'#'+id, info.VideoName, info);
},
helpers: {
overlay: {
locked: false
}
}
});
I need show iframe youtube and after it show any HTML code. How to do? I tried in method:
afterLoad:function(){
// $('.fancy-content').html('<b>Any....</b>');
}
But this case clear my iframe...
Also tried:
afterLoad:function(){
$('.fancybox-inner').append(template);
}
It is works, but I dont see content, its hidden, the block .fancybox-inner
has height = 600px, but content is more than 600px, so I dont see...
Try to refresh your fancybox (Your iframe needs to be placed inside "fancybox-inner" and display block to make this work) once the iframe is loaded (no need for wait until its loaded if your iframe has a static height).
An other solution is, to load your iframe into your
.fancybox-inner
inbeforeLoad
-event function. In that way, the fancybox should size the content right.You could use the fancybox
title
to add any html content you want, you just need to set that html content inside a variable like :... or inside of a (hidden) html
<div>
like :... and pull that content inside the
beforeLoad
callback (using the second option) likeNow, based on your jsfiddle, if you want to call fancybox from this html
... you may want to tweak it like
Notice I changed
data="{youtube URL}"
intodata-fancybox-href="{youtube URL}"
so fancybox will know where to get the content from.Also notice that if the URL has this format
... you don't actually need the
replace()
method to convert it.After, get the different values (
width
,height
, etc) from thedata
attributes inside thebeforeLoad
callback like :Notice
this.href
,this.title
,this.width
andthis.height
refer to default values of fancybox that can be overridden inside the callback.Also notice that
this.href
gets its value from the specialdata-fancybox-href
attribute (in your html) but we are overriding it to add the varinfo
with your youtube trailing parameters.See full code in JSFIDDLE
No need to sweat trying to resize fancybox after adding the content.