Last active
September 18, 2022 05:36
-
-
Save koistya/7eac879f674ae9f5e26c to your computer and use it in GitHub Desktop.
Modal dialog with a YouTube player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<script src="http://code.jquery.com/jquery.min.js"></script> | |
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
</head> | |
<body> | |
<!-- Open a modal dialog button --> | |
<a href="#" data-toggle="modal" data-target=".video-dialog">How to Use Ask the Experts</a> | |
<!-- Video Player Dialog --> | |
<div class="modal fade video-dialog" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true"> | |
<div class="modal-dialog modal-lg"> | |
<div class="modal-content"> | |
<div class="modal-body"> | |
<div id="videoDialogPlayer" class="vidflex"></div> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script> | |
(function () { | |
var el = document.createElement('script'); | |
el.src = "//www.youtube.com/iframe_api"; | |
var s = document.getElementsByTagName('script')[0]; | |
s.parentNode.insertBefore(el, s); | |
var videoDialogPlayer; | |
window.onYouTubeIframeAPIReady = function () { | |
videoDialogPlayer = new YT.Player('videoDialogPlayer', { | |
height: '390', | |
width: '640', | |
videoId: '4HG6Ek_SyJs' | |
}); | |
} | |
$(function () { | |
$('.video-dialog').on('shown.bs.modal', function () { | |
videoDialogPlayer.playVideo(); | |
}).on('hide.bs.modal', function () { | |
videoDialogPlayer.stopVideo(); | |
}); | |
}); | |
}()); | |
</script> | |
</body> | |
</html> |
how to set autoplay???
I have two modals with diferents videos on the same page and just work for the first one.
How can I make work the second one?
I was trying to do a for each but it doesnt work :(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have one that works with Vimeo?