用youtube视频替换图像

时间:2011-05-03 14:59:17

标签: youtube frame poster

我有一张图片,我希望将图片链接到嵌入的YouTube视频,这样,如果用户点击图片,它就会开始在图片所在的位置播放。有关如何实现这一目标的任何想法?

谢谢,

大卫

2 个答案:

答案 0 :(得分:4)

将嵌入的视频放在不可见的div中:

<div id="video" style="display: none;"> embedded video code here </div>

然后给img一个id:

<img id="videopic" src="videopic.jpg" alt="Video Picture" />

然后,在图像周围放置一个指向隐藏图像并显示嵌入视频的JavaScript的链接:

<a href="javascript:document.getElementById('video').style.display = 'block'; document.getElementById('videopic').style.display = 'none'; void(0);">
<img id="videopic" src="videopic.jpg" alt="Video Picture" />
</a>

所以,完整的代码是:

<div id="video" style="display: none;"> embedded video code here </div>
<a href="javascript:document.getElementById('video').style.display = 'block'; document.getElementById('videopic').style.display = 'none'; void(0);">
<img id="videopic" src="videopic.jpg" alt="Video Picture" />
</a>

答案 1 :(得分:0)

<div id="hideThisUltraCoolVideoFromYou" style="display:none;">
<object style="height: 390px; width: 640px">
<param name="movie" value="http://www.youtube.com/v/V4jZ_BV4MQ4?version=3&autoplay=1">
<param name="allowFullScreen" value="true">
<param name="allowScriptAccess" value="always">
<embed src="http://www.youtube.com/v/V4jZ_BV4MQ4?version=3&autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>
</div>
<img style="width:640px;height:390px;cursor:pointer;" src="thisPictureInsteadOfVideo.jpg" onclick="this.style.display='none';document.getElementById('hideThisUltraCoolVideoFromYou').style.display='block';" />

这样的事情:)