我正在开发一个网站,主页上有一些嵌入的YouTube视频。直到最近,这些视频效果很好,但现在看来它们已经不再适用了!它从YouTube获取视频,但我无法播放任何视频。
我将代码与早期版本进行了比较,代码仍然相同。我一直在寻找并抓住这个问题几个小时试图找出它为什么不再起作用。这是一个带有我正在使用的代码的JSFiddle。 https://jsfiddle.net/ftmLsaym/
我需要做些什么才能解决这个问题?
HTML
<div class="splashdiv">
<iframe id="teaser" src="https://www.youtube.com/embed/PNT39y4N4H4?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
<div style="width: 100%">
<button style="width:50%;float:left" onclick="previousVideo()">Previous</button>
<button style="width:50%;float:right" onclick="nextVideo()">Next</button></div>
CSS
.splashdiv {
position: relative;
width: 100%;
height: 0;
padding-bottom: 51%;
z-index:-1;
}
.splashdiv iframe {
position: absolute;
width: 100%;
height: 100%;
left: 0; top: 0;
}
JS
var frame = document.getElementById('teaser');
var pos = 0;
var src = [
"https://www.youtube.com/embed/PNT39y4N4H4?rel=0",
"https://www.youtube.com/embed/M--kEKu8-IE?rel=0",
"https://www.youtube.com/embed/3wgd8fHidzg?rel=0",
"https://www.youtube.com/embed/2yf4bUW9mlE?rel=0",
"https://www.youtube.com/embed/CueAcWRsaY8?rel=0",
"https://www.youtube.com/embed/ulsa6Aog7Yw?rel=0",
"https://www.youtube.com/embed/7qTp3lk7gt4?rel=0"
]
function nextVideo() {
if (pos < 6) {
pos += 1;
showVideo();
}
}
function previousVideo() {
if (pos > 0) {
pos -= 1;
showVideo();
}
}
function showVideo() {
frame.src = src[pos];
}
function barnaby() {
pos = 1;
frame.src = src[pos]+"&autoplay=1";
}
答案 0 :(得分:1)
z-index
太低,你需要增加它,它在另一个div
后面显示了一个解决方案,虽然你不需要使用200,只是一个例如:)https://jsfiddle.net/ftmLsaym/5/
答案 1 :(得分:0)
将iframe移出splashdiv - 应该让视频运行。
答案 2 :(得分:0)
用此
替换您的.splashdiv {
position: relative;
width: 100%;
height: 0;
padding-bottom: 51%;
z-index:2;
}
css代码
public static Object getPerson(){
答案 3 :(得分:0)
只需删除此行:
z-index:-1
z-index:-1
将整个.splashdiv
div(包括iframe)设置为正文图层后面。因此,YouTube iframe无法捕获您的鼠标点击。