【发布时间】:2014-04-22 23:39:19
【问题描述】:
我正在尝试为 YouTube 视频创建自己的海报图片。我希望在点击海报图片时开始播放视频。这个想法是将嵌入代码存储在包含海报图像的 DIV 的属性中,当单击该框时,图像被删除,嵌入代码被拉出并插入。这里有一个 jsfiddle - http://jsfiddle.net/3JAxB/12/
但我无法让 autostart=1 工作(Ready 代码的第二行)。当我单击图像时,我总是会在开始之前等待播放的视频。
有人发现问题了吗?
谢谢
$(function(){ // Ready
$('div#video').attr('embed_code', "<iframe width='854' height='510' src='//www.youtube.com/embed/Q1PY_7GNfIw' frameborder='0' allowfullscreen></iframe>");
// $('div#video').attr('embed_code', "<iframe width='854' height='510' src='//www.youtube.com/embed/Q1PY_7GNfIw?autostart=1' frameborder='0' allowfullscreen></iframe>");
})
$('#video').click(function () {
var this$ = $(this);
var embedCode = this$.attr('embed_code');
this$.find('.poster').remove(); // remove poster image
this$.prepend(embedCode); // put in the YouTube video
});
【问题讨论】:
-
见stackoverflow.com/questions/5349716/… 你需要使用 autoplay=1 而不是自动启动
标签: jquery youtube-api