在Fancybox jQuery中打开YouTube视频 [英] Open youtube video in Fancybox jquery
问题描述
我可以在fancybox中打开youtube视频吗?
Can I open youtube video in fancybox.
我有一个youtube视频链接列表,例如:
I have a list of youtube videos links , for ex:
<a href="http://www.youtube.com/watch?v=PvbqV8W96D0" class="more">Play</a>
和fancybox:
$("a.more").fancybox({
'titleShow' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic'
});
我不想为每个视频创建新的嵌入对象.
I don't want to create for each video new embed object.
是否有插件,或者有其他方法吗?
Is there some plug in, or a other way to do that ?
推荐答案
已损坏,请参见编辑
<script type="text/javascript">
$("a.more").fancybox({
'titleShow' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
'type' : 'swf',
'swf' : {'wmode':'transparent','allowfullscreen':'true'}
});
</script>
通过这种方式,如果启用了用户javascript,则会打开带有youtube嵌入视频的fancybox;如果禁用了javascript,则会打开视频的youtube页面.如果需要,可以添加
This way if the user javascript is enabled it opens a fancybox with the youtube embed video, if javascript is disabled it opens the video's youtube page. If you want you can add
target="_blank"
对于您的每个链接,它不会在大多数文档类型上生效,但是如果fancybox不选择链接,它将在新窗口中打开该链接.
to each of your links, it won't validate on most doctypes, but it will open the link in a new window if fancybox doesn't pick it up.
this
未被正确引用,因此该代码在this
下找不到href
.您必须这样称呼它:
this
, above, isn't referenced correctly, so the code won't find href
under this
. You have to call it like this:
$("a.more").click(function() {
$.fancybox({
'padding' : 0,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'title' : this.title,
'width' : 680,
'height' : 495,
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
'type' : 'swf',
'swf' : {
'wmode' : 'transparent',
'allowfullscreen' : 'true'
}
});
return false;
});
在上面复制的 http://fancybox.net/blog #4中进行了介绍
as covered at http://fancybox.net/blog #4, replicated above
这篇关于在Fancybox jQuery中打开YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!