在一个Fancybox库中使用不同类型的标题

我今天提出一个话题,因为插件Fancybox 2.0( http://fancyapps.com/fancybox/ )存在问题。

事实上,根据目前在fancybox中的媒体,我想设置不同类型的标题。 如果我的Fancybox中有iFrame,则标题必须为“outside”。 否则,如果它是其他媒体,标题必须“结束”。

$(".fancybox").fancybox({openEffect: 'elastic',closeEffect: 'elastic',beforeShow: function() { share_buttons_fancybox = ''; if (this.title) { this.title += share_buttons_fancybox; } else { this.title = share_buttons_fancybox; } },afterShow: function() { twttr.widgets.load(); FB.XFBML.parse(); addthis.toolbox(); addthis.toolbox(".addthis_toolbox"); addthis.counter(".addthis_counter"); },helpers: {thumbs: {width: 80,height: 45},title: {type: 'over'}},padding: 0}) 

有任何想法吗 ? iFrame和其他媒体必须在同一个Fancybox galery中。 🙂

谢谢你提前,对不起我的英语(我是法国人):)

您可以使用helpers选项将所有元素的title位置设置为over ,并使用$.extend()回调中的jQuery的$.extend()方法将iframe元素的title位置设置为outside

 $(".fancybox").fancybox({ padding: 0, openEffect: 'elastic', closeEffect: 'elastic', helpers: { thumbs: { width: 80, height: 45 }, title: { type: 'over' // all media } }, afterLoad: function () { if (this.type == "iframe") { $.extend(this, { helpers: { title: { type: 'outside' // iframe only }, overlay: { locked: false // needed to fix a bug while closing (can be true or false) } } }); } } }); 

请注意 ,我在$.extend()方法中设置了overlay locked选项,以便在关闭fancybox时解决错误:

 overlay: { locked: false } 

如果没有这个,叠加层将不会关闭(需要再次click才能关闭)

请参阅JSFIDDLE