Skip to content

Instantly share code, notes, and snippets.

@pelid
Created March 30, 2017 15:32
Show Gist options
  • Save pelid/60b3d641e97f2ca6da6d5e6d3dc49e62 to your computer and use it in GitHub Desktop.
Save pelid/60b3d641e97f2ca6da6d5e6d3dc49e62 to your computer and use it in GitHub Desktop.
<script>
function onYouTubeIframeAPIReady() {
$modal.on('show', function(){
new YT.Player('player', {
height: '360',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
}
});
}
function onPlayerReady(event) {
var player = event.target
if ($modal.isVisible()){
player.playVideo();
} else {
$modal.on('show', function(){
player.playVideo();
})
}
$modal.on('closed', function(){
player.stopVideo();
})
})
}
</script>
<script async defer src="https://www.youtube.com/iframe_api"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment