【问题标题】:Autoplay embedded Youtube video with Fancybox使用 Fancybox 自动播放嵌入的 Youtube 视频
【发布时间】:2011-07-06 18:05:48
【问题描述】:

我的页面上有一个链接图像,点击它会加载一个 Fancybox 模态框。它成功地做到了,但我希望视频自动播放。如果我将 YouTube URL 设置为 autoplay=1,隐藏的 DIV 会在页面加载时在后台播放。

// Here is the linked image
<a id="inline" href="#video"><img src="someimage.jpg" alt="Description" /></a>

// Here is the hidden DIV
<div style="display:none">
  <div id="video">
    <iframe title="YouTube video player" width="640" height="390" src="###YOUTUBE LINK###rel=0&amp;hd=1&amp;autoplay=0" frameborder="0"></iframe>
  </div>
</div>

// Here is the script
<script type="text/javascript">
  $("a#inline").fancybox({
    'hideOnContentClick': true,
  });
</script>

我的猜测是我需要做一些 Bind() 事件和字符串替换来将 autoplay=0 更改为 autoplay=1 但我尝试了一些变体但没有成功

有什么想法吗?

【问题讨论】:

    标签: jquery replace youtube fancybox


    【解决方案1】:

    首先将链接图片的 href 更改为您的 YouTube 网址,确保“autoplay=1”like this link(不是嵌入网址)。然后摆脱隐藏的&lt;div&gt; 和follow tip 4 on the FancyBox "Tips & Tricks" page,这很简单:

    $("#tip4").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;
    });
    

    这样做,人们仍然可以观看视频,即使 JS 对他们禁用。

    【讨论】:

    • 我曾尝试过基于技巧 #4 的类似操作,但它只是加载了一个 Fancybox 模态框,其中没有任何内容。右键单击该区域显示“电影未加载”
    • 嗯,好的,修好了。您只需要正常的 URL 即可,而不是嵌入的链接。都解决了。谢谢!
    • 是的,我第一次也花了一段时间才弄明白。
    猜你喜欢
    • 2017-11-03
    • 2018-05-25
    • 2021-05-01
    • 2015-05-05
    • 2018-12-16
    • 2013-10-29
    • 2014-04-21
    • 2013-07-21
    相关资源
    最近更新 更多