I created a simple slider four the college and I cant get videos to pause when switching between them. Does anyone know what I'm doing wrong? The goal is to have any currently playing video stop when you click on the same or another video's thumbnail.
I've looked into using the youtube APIs but every example seems to use a click event as the trigger and when I add that code to my existing click events nothing seems to work in tearms of pausing the video.
<style>
.video-slider-2, .video-slider-3, .video-slider-4 {display:none}
</style>
</headcode> <!-- before closing head tag -->
<bodycode></bodycode> <!-- after opening body tag -->
<footcode>
<script type="text/javascript">
function swapvid1() {
document.getElementsByClassName('video-slider-1')[0].style.display = "inline";
document.getElementsByClassName('video-slider-2')[0].style.display = "none";
document.getElementsByClassName('video-slider-3')[0].style.display = "none";
document.getElementsByClassName('video-slider-4')[0].style.display = "none";
$('.youtube-iframe').each(function(index) {
$(this).attr('src', $(this).attr('src'));
return false;
});
}
function swapvid2() {
document.getElementsByClassName('video-slider-1')[0].style.display = "none";
document.getElementsByClassName('video-slider-2')[0].style.display = "inline";
document.getElementsByClassName('video-slider-3')[0].style.display = "none";
document.getElementsByClassName('video-slider-4')[0].style.display = "none";
$('.youtube-iframe').each(function(index) {
$(this).attr('src', $(this).attr('src'));
return false;
});
}
function swapvid3() {
document.getElementsByClassName('video-slider-1')[0].style.display = "none";
document.getElementsByClassName('video-slider-2')[0].style.display = "none";
document.getElementsByClassName('video-slider-3')[0].style.display = "inline";
document.getElementsByClassName('video-slider-4')[0].style.display = "none";
$('.youtube-iframe').each(function(index) {
$(this).attr('src', $(this).attr('src'));
return false;
});
}
function swapvid4() {
document.getElementsByClassName('video-slider-1')[0].style.display = "none";
document.getElementsByClassName('video-slider-2')[0].style.display = "none";
document.getElementsByClassName('video-slider-3')[0].style.display = "none";
document.getElementsByClassName('video-slider-4')[0].style.display = "inline";
$('.youtube-iframe').each(function(index) {
$(this).attr('src', $(this).attr('src'));
return false;
});
}
document.getElementById('video-thumb-1').onclick = function () {
swapvid1();
};
document.getElementById('video-thumb-2').onclick = function () {
swapvid2();
};
document.getElementById('video-thumb-3').onclick = function () {
swapvid3();
};
document.getElementById('video-thumb-4').onclick = function () {
swapvid4();
};
</script>
<div class="video-slider-1">
</div>
<div class="video-slider-2">
<iframe id="popup-youtube-player-1" width="560" height="315" src="https://www.youtube-nocookie.com/embed/ajEtUxjgXJk?rel=0" frameborder="0" allowfullscreen="true" allowscriptaccess="always"></iframe>
</div>
<div class="video-slider-3">
<iframe id="popup-youtube-player-3" width="560" height="315" src="https://www.youtube-nocookie.com/embed/BYpsEdYNyB0?rel=0" frameborder="0" allowfullscreen="true" allowscriptaccess="always"></iframe>
</div>
<div class="video-slider-4">
<iframe id="popup-youtube-player-4" width="560" height="315" src="https://www.youtube-nocookie.com/embed/xusKGsLyoNA?rel=0" frameborder="0" allowfullscreen="true" allowscriptaccess="always"></iframe>
</div>
<div class="video-slider-thumb-1">
<div class="col-xs-3 col-sm-3 col-md-3">
<a class="" id="video-thumb-1"><img class="responsive-image" src="{{f:10952848}}" alt="Promise for Today Video Thumbnail" /></a>
</div>
</div>
<div class="video-slider-thumb-2">
<div class="col-xs-3 col-sm-3 col-md-3">
<a id="video-thumb-2"><img class="responsive-image" src="{{f:7618238}}" alt="Promise of Opportunity Video Thumbnail" /></a>
</div>
</div>
<div class="video-slider-thumb-3">
<div class="col-xs-3 col-sm-3 col-md-3">
<a id="video-thumb-3"><img class="responsive-image" src="{{f:13134177}}" alt="Thank You Video Thumbnail" /></a>
</div>
</div>
<div class="video-slider-thumb-4">
<div class="col-xs-3 col-sm-3 col-md-3">
<a id="video-thumb-4"><img class="responsive-image" src="{{f:4121391}}" alt="Promise of Innovation and Partnership Video Thumbnail" /></a>
</div>
</div>
` . `$('.video-thumb')` is not defined before
– Bertrand Martel Oct 12 '17 at 14:05