所以基本上我有一个单页网站,里面有一大堆隐藏的 Vimeo 视频。我需要所有视频在未显示时暂停。
到目前为止,我可以在单击特定锚标签时暂停一个视频,但我希望能够通过单击任何 a 标签来暂停所有视频。
我尝试了很多不同的东西,但由于我对 JavaScript 的了解有限,我觉得我已经超出了我的深度。
任何指针将不胜感激。
<script>
function showonlyone(thechosenone) {
var newboxes = document.getElementsByTagName("div");
for(var x=0; x<newboxes.length; x++) {
name = newboxes[x].getAttribute("name");
if (name == 'newboxes') {
if (newboxes[x].id == thechosenone) {
newboxes[x].style.display = 'block';
}
else {
newboxes[x].style.display = 'none';
}}}}
</script>
<div name="newboxes" id="newboxes0" style="display: block;">
<iframe id="player" src="http://player.vimeo.com/video/53407474?api=1&player_id=player" width="800" height="450" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
</div>
<div name="newboxes" id="newboxes0" style="display: none;">
<iframe id="player" src="http://player.vimeo.com/video/53855813?api=1&player_id=player" width="800" height="450" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
</div>
<div name="newboxes" id="newboxes0" style="display: none;">
<iframe id="player" src="http://player.vimeo.com/video/19780095?api=1&player_id=player" width="800" height="450" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
</div>
<a name="button" id="button1" href="javascript:showonlyone('newboxes0');"><span></span></a>
<a name="button" id="button2" href="javascript:showonlyone('newboxes1');"><span></span></a>
<a name="button" id="button3" href="javascript:showonlyone('newboxes2');"><span></span></a>
<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
<script>
function ready(player_id) {
var player = $f(player_id);
pauseButton = document.getElementById('button1');
pauseButton.addEventListener('click', function() {
player.api('pause');
});}
window.addEventListener('load', function() {
$f(document.getElementById('player')).addEvent('ready', ready);
});
</script>