在 Fancybox jQuery 中打开 YouTube 视频 [英] Open YouTube video in Fancybox jQuery

查看:29
本文介绍了在 Fancybox jQuery 中打开 YouTube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 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>

和花式盒子:

$("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 ?

推荐答案

THIS IS BROKEN, SEE EDIT

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆