【问题标题】:Youtube Overlay Image Div - Autoplay UnderneathYoutube Overlay Image Div - 下方自动播放
【发布时间】:2012-08-16 21:14:08
【问题描述】:

我在这个 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>

【问题讨论】:

    标签: html iframe youtube onclick overlay


    【解决方案1】:

    点击后,添加:

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

    【讨论】:

    • 谢谢 UnLoCo,你能不能用通俗的话来解释一下?我是游戏新手!
    • 您好,这段代码将 iframe src 属性上的 autoplay=0 替换为 autoplay=1;这意味着它将使 iframe 重新加载并自动播放。
    • 这是你的意思吗? '' 然后是 Youtube 链接?
    • 啊好吧,我只是不明白如何有一个空白的 iframe src,然后有 Youtube 作为 src。我是制作 2 个 iframe,还是有 2 个 src 目的地?谢谢你的建议:)
    • 不,不要那样做,就像我说的那样,我改变了答案。我在第二条评论中解释了它。
    猜你喜欢
    • 2018-11-21
    • 1970-01-01
    • 2015-09-25
    • 2023-03-23
    • 2011-04-29
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多