【发布时间】:2019-10-06 02:09:37
【问题描述】:
我已经集成了插件https://github.com/pupunzi/jquery.mb.YTPlayer,按照文档示例,我无法自动启动视频,用户必须点击播放。
有一种方法可以模拟这种点击,或者有一些解决方案可以让视频在没有任何用户操作的情况下开始加载。
示例完整代码: https://jsfiddle.net/py7bkox3/
HTML
<div id="video"></div>
<div id="ctn">
<h1>TITLE EXAMPLE</h1>
</div>
Javascript:
// When the document is ready
$(document).ready(function(){
// Initialize YouTube player
$("#video").YTPlayer({
// URL of the YouTube video
videoURL:'https://youtu.be/BsekcY04xvQ',
// If you want it as background of your website
// or of an element e.g #elementId
containment: "#ctn",
autoplay: true,
controls: 0,
mute: true,
startAt: 0,
opacity: 1,
// Hide YouTube Controls
showControls: false,
onReady: function(){
},
onError: function(err){
console.log("An error ocurred", err);
}
});
});
CSS
#ctn {
display: block;
margin: 0;
padding: 250px 0 !important;
width: 100%;
}
【问题讨论】:
标签: javascript jquery html css youtube