【发布时间】:2013-08-19 12:22:15
【问题描述】:
所以我正在做一些小技巧,以便在嵌入的 YouTube 视频(YouTube 给我作为 iFrame)的顶部显示静止图像。这个想法是用户将单击静态图像(上面演示中的一个大彩色框),然后我使用 jQuery 隐藏图像并将 iFrame 放置在它所在的位置。我将视频设置为自动播放并开始播放。
代码很简单,就是这几个视频块:
<div class='videoblock yellow'>
<div data-videoid="7ZLywQpPgcA" class='overlay'>Click this text to play</div>
<div class="thevideo"></div>
</div>
然后是初始化同位素的代码,以及点击时交换 YouTube 视频的事件处理程序:
$(function() {
$('#iso').isotope({ itemSelector : '.videoblock' });
});
// when the user clicks, hide the overlay, put the html code in for the iFrame and show it
$('.overlay').click(function() {
vid = $(this).data('videoid');
h = '<iframe width="435" height="265" src="//www.youtube.com/embed/'+vid+'?autoplay=1" frameborder=0 allowfullscreen></iframe>';
$(this).hide(); $(this).next().show().html(h);
});
jsfiddle 现场演示:http://jsfiddle.net/pnoeric/MeL7a/7/
问题是这种技术在 Chrome (Mac) 和 Safari 中效果很好,但在 Firefox 中,点击对 YouTube 中的视频没有任何影响。暂停按钮不起作用,即使 YouTube 可以看到我将鼠标悬停在该按钮上。
这是为什么?我该如何解决? :-)
(我也愿意采用任何更好的技术在 YouTube 视频上显示静止图像...)
【问题讨论】:
-
Duopixel 的解决方案是将
&html5=1添加到 YouTube 嵌入 URL。 Firefox supports HTML5 video 回到 3.5 版,所以应该是安全的。
标签: jquery firefox iframe jquery-isotope