2013-07-01 87 views
0

我目前有fancybox显示所有正确的图片/视频,它应该。但是,我似乎无法得到它显示每次调用fancybox相关的标题。为fancybox图片添加标题/视频

我使用的fancybox V2.1.5

$(document).ready(function(){ 
$(".fancyYoutube").live('click',function(){ 
$.fancybox({ 
'transitionIn' : 'elastic', 
'transitionOut' : 'elastic', 
'titleShow' : 'true', 
'speedIn' : '100', 
'width' : 680, 
'height' : 395, 
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'), 
'type' : 'swf', 
'swf' : { 
'wmode' : 'transparent', 
'allowfullscreen' : true, 
}, 
beforeLoad: function() { 
this.title = $(this.element).attr('caption'); 
} 
}); 
return false; 
}); 
}); 

我使用它需要的部分内caption=,但它仍然不显示字幕文本:(

我也是采用了最新的jQuery插件吧。

任何帮助将是巨大的,谢谢!

编辑:问题就迎刃而解了:

$(document).ready(function(){ 
$(".fancyYoutube").live('click',function(){ 
$.fancybox({ 
'transitionIn' : 'elastic', 
'transitionOut' : 'elastic', 
'title' : this.title, 
'speedIn' : '100', 
'width' : 680, 
'height' : 395, 
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'), 
'type' : 'swf', 
'swf' : { 
'wmode' : 'transparent', 
'allowfullscreen' : true 
} 
}); 
return false; 
}); 
}); 

只需要title : this.title,

回答

0

如果我记得很清楚(我查了这里太:http://fancybox.net/blog),你需要这些参数

'titlePosition'   : 'inside', 
'titleFormat'  : formatTitle 

凡formatTitle是一个函数,它添加标题

function formatTitle(title, currentArray, currentIndex, currentOpts) { 
    return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/data/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '') + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>'; 
} 

I觉得有什么错在这里

this.title = $(this.element).attr('caption'); 

尝试使用IDS有这样的事情(只要它不适合使用适当的ID)

$(this).html($(this).attr('caption')); 
+0

我是正确的是'标题='将需要更改为'标题='? 此外,我也发现了博客部分,但它甚至不允许加载fancybox。 http://pastebin.com/ND0GNXYk是正确的吗? –

+0

事实上,我不认为你使用任何问题,因为.attr('标题')采取任何你告诉它。 检查我的编辑 – MayTheSchwartzBeWithYou

+0

现在已经改变了我的代码以包含'beforeLoad:function(){ $(this).html($(this).attr('caption')); }''而不是'this.title = $(this.element).attr('caption');'和fancybox现在不加载,只是链接到图像/视频 –