私はいくつかのYouTube動画を1つのページに持ち、CSSを使用して選択した動画を表示し、他の動画に切り替えることができます。私は適切なソースコードを見つけられず、既存のものを編集して自分のニーズを満たす経験がないので、jQueryの使用を避けようとしています。問題は、1つのビデオを再生して次のビデオに移動すると、ビデオを隠して表示しているためです。元のビデオがまだ再生されているため、オーディオのクロスオーバーが発生し、多くのビデオでPCが減速します。 Youtubeビデオは "k"キーボードストロークで一時停止することができるので、リンクに「accesskey」機能を追加して一時停止しました。しかし、私はアクセスキーがアクティブになる前にブラウザが隠れていると思うので、ビデオはバックグラウンドで再生し続けます。アクセスキーはアクティブなビデオの再生でのみ機能するからです。私の問題を解決するためのアドバイスや助言。YouTube動画を停止するコードはありますか?
ウェブサイト(ライブ例): http://s187242710.onlinehome.us/tdsa/resources.php
HTML:
<script>
function show(id) {
var item = document.getElementById(id);
var all = document.getElementsByClassName('hidden');
for(var i=0; i<all.length; i++)all[i].style.display = 'none';
if(item)item.style.display = 'block';
}
</script>
<h1>Practice Techniques</h1>
<div class="resourcecontainer">
<a href="javascript:show('test2');">
<img class="resourceimage" src="images/sampleresource.jpg" width="190" height="120" border="0">
</a>
</div>
<div class="resourcecontainer">
<a href="javascript:show('test3');">
<img class="resourceimage" src="images/sampleresource.jpg" width="190" height="120" border="0">
</a>
</div>
<div class="resourcecontainer">
<a href="javascript:show('test4');">
<img class="resourceimage" src="images/sampleresource.jpg" width="190" height="120" border="0">
</a>
</div>
<div class="resourcecontainer">
<a href="javascript:show('test5');">
<img class="resourceimage" src="images/sampleresource.jpg" width="190" height="120" border="0">
</a>
</div>
<br><br>
<h1>Equipment Selection</h1>
<div class="resourcecontainer"><img class="resourceimage" src="images/sampleresource.jpg" width="190" height="120" border="0"></div>
<div class="resourcecontainer"><img class="resourceimage" src="images/sampleresource.jpg" width="190" height="120" border="0"></div>
<div class="resourcecontainer"><img class="resourceimage" src="images/sampleresource.jpg" width="190" height="120" border="0"></div>
<div class="resourcecontainer"><img class="resourceimage" src="images/sampleresource.jpg" width="190" height="120" border="0"></div>
<br><br>
<div id="test1" class="hidden">
</div>
<div id="test2" class="hidden">
<div class="resourcevideo">
<div class="videolink"><a href="javascript:show('test1');">(Previous)</a></div>
<div class="videolink"><a href="javascript:show('test1');" accesskey="k">[Close]</a></div>
<div class="videolink"><a href="javascript:show('test3');">(Next)</a></div>
<iframe class="centervideo" width="550" height="350" src="https://www.youtube.com/embed/EO4-B_ttHe0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div id="test3" class="hidden">
<div class="resourcevideo">
<div class="videolink"><a href="javascript:show('test2');">(Previous)</a></div>
<div class="videolink"><a href="javascript:show('test1');" accesskey="k">[Close]</a></div>
<div class="videolink"><a href="javascript:show('test4');">(Next)</a></div>
<iframe class="centervideo" width="550" height="350" src="https://www.youtube.com/embed/XiGt0X0csoE" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div id="test4" class="hidden">
<div class="resourcevideo">
<div class="videolink"><a href="javascript:show('test3');">(Previous)</a></div>
<div class="videolink"><a href="javascript:show('test1');">[Close]</a></div>
<div class="videolink"><a href="javascript:show('test5');">(Next)</a></div>
<iframe class="centervideo" width="550" height="350" src="https://www.youtube.com/embed/XnbPGKB34bU" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div id="test5" class="hidden">
<div class="resourcevideo">
<div class="videolink"><a href="javascript:show('test4');">(Previous)</a></div>
<div class="videolink"><a href="javascript:show('test1');">[Close]</a></div>
<div class="videolink"><a href="javascript:show('test2');">(Next)</a></div>
<iframe class="centervideo" width="550" height="350" src="https://www.youtube.com/embed/qiZOkhJ_wnY" frameborder="0" allowfullscreen></iframe>
</div>
</div>
CSS:
.resourcecontainer {
width:210px;
height:140px;
float:left;
background-color:#EDEDED;
margin-right: 20px;
text-align:center;
margin-bottom:25px;
border-radius: 10px;
}
.resourceimage {
border:solid 1px;
border-color:#A5A5A5;
margin-top: 10px;
}
.resourcevideo {
clear: both;
width: 600px;
height: 450px;
color:#FFFFFF;
background-color: #000000;
z-index: 9999;
position:absolute;
top: 50%;
left: 50%;
margin-left: -300px;
margin-top: -210px;
}
.centervideo {
margin: 25px;
}
.videolink {
color: #FFFFFF;
padding: 0px;
margin: 0px;
font-size:24px;
font-weight:bold;
background-color:#AA3537;
width: 200px;
height: 50px;
float: left;
text-align:center;
line-height: 50px;
display: block;
}
.videolink a {
text-decoration:none;
color:#FFFFFF;
}
.videolink a:hover {
color:#000000;
}
.hidden {
display:none;
}
#test1 {
display: block;
}
[Youtube Player API](https://developers.google.com/youtube/js_api_reference#Queueing_Functions)を使用できます。 –