【发布时间】:2016-10-15 14:09:57
【问题描述】:
我正在尝试播放 youtube 视频以在 iframe 标记处于焦点时自动播放。尝试了以下但它不工作。我的 jquery 出错了? 我想将 &autoplay=1 添加到 iframe 的 src 中,当它是焦点时。
HTML :-
<div class="vid-wrapper" >
<iframe width="100%" height="100%" id="video1" src="https://www.youtube.com/embed/bxgorUGjCIw?rel=0" frameborder="0" allowfullscreen scrolling="auto" ></iframe>
</div>
CSS :-
.vid-wrapper{
width: 100%;
position: relative;
padding-bottom: 56.25%;
height: 0;
z-index:-20;
}
.vid-wrapper video, .vid-wrapper iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index:-1;
}
jQuery :-
$(document).ready(function() {
$("#video1").mouseenter(function(){
$(this).attr("src",$(this).attr("src") + "&autoplay=1");
});
$("#video1").mouseleave(function(){
var src= $(this).attr("src");
var arr_str = src.split("&");
$(this).attr("src",arr_str[0]);
});
});
有什么帮助吗?提前致谢。
【问题讨论】:
标签: jquery