Youtube Overlay Image Div - 自动播放下方

时间:2012-08-16 21:14:09

标签: html iframe youtube onclick overlay

我在homepage上的YouTube iframe上有一个div叠加层。

这个想法是你点击一次然后视频会自动播放,但是我无法让它播放。当我设置YouTube参数'autoplay = 1'时,视频会在图像下方播放,甚至不会点击它。

以下是我在下面使用的代码;

<div onclick="thevid=document.getElementById('thevideo');
thevid.style.display='block'; 
this.style.display='none'">

<img style="cursor: pointer;"
src="http://www.belfastdigitalagency.com/wp-content/themes/responsy-v2.5/random_image1.php"
alt="belfast digital marketing agency animated video" />
</div>

<div id="thevideo" style="display: none;">
<iframe width="1280" height="720"
src="http://www.youtube.com/embed/iy_lolGhjPE?rel=0&vq=hd720&color=white&autoplay=0&wmode=transparent&theme=light&showinfo=0&origin=http://www.belfastdigitalagency.com"
frameborder="0" allowscriptaccess="always"
allowfullscreen="true"></iframe>
</div>

任何想法出了什么问题?非常感谢,即使它只是一个指出看看看起来很糟糕的东西!

干杯,

菲尔

P.S - 感谢UnLoCo的传说,它很快就被修复了。这是要纠正的最终代码。再次感谢UnLoCo!

<div onclick="thevid=document.getElementById('thevideo');
thevid.style.display='block'; this.style.display='none'; 
document.getElementById('iframe').src = 
document.getElementById('iframe').src.replace('autoplay=0','autoplay=1');">

<img style="cursor: pointer;" src="http://www.belfastdigitalagency.com/wp-content/themes/responsy-v2.5/random_image1.php" alt="belfast digital marketing agency animated video" />
</div>

<div id="thevideo" style="display: none;">
<iframe id="iframe" width="1280" height="720" src="http://www.youtube.com/embed/iy_lolGhjPE?rel=0&vq=hd720&color=white&autoplay=0&wmode=transparent&theme=light&showinfo=0&origin=http://www.belfastdigitalagency.com"
frameborder="0" allowscriptaccess="always" allowfullscreen="true"></iframe>
</div>

1 个答案:

答案 0 :(得分:7)

点击

,添加:

document.getElementById('iframe').src = 
document.getElementById('iframe').src.replace('autoplay=0','autoplay=1');