Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var youtubeScriptTag = document.createElement('script');
youtubeScriptTag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(youtubeScriptTag, firstScriptTag);
var deviceRatio = ($(document).width())/($(document).height());
$(window).resize(function(){
var currDeviceRatio = ($(document).width())/($(document).height());
if(currDeviceRatio != deviceRatio && youtubePlayer && typeof youtubePlayer.stopVideo !== "undefined"){
//youtubePlayer.setSize(parseInt($(document).width() * 0.75), parseInt($(document).height() * 0.5));
}
});
});
function onYoutubePlayerReady(event){
event.target.stopVideo();
}
function onYoutubePlayerStateChange(event){
console.log("State Change -> ", event);
if (event.data == YT.PlayerState.PLAYING && !isCongreat) {
youtubePlayer.stopVideo();
}
}
function onYouTubeIframeAPIReady() {
var width_youtube = parseInt($(document).height() * 0.4 *1.77);
var maxwidth = parseInt($(document).width());
if(width_youtube>maxwidth){
width_youtube = parseInt($(document).width() * 0.75);
}
youtubePlayer = new YT.Player('congreat-youtube-player', {
height: parseInt($(document).height() * 0.4),
width: parseInt(width_youtube),
videoId: 't_gUBY3K-JE',
events: {
'onReady': onYoutubePlayerReady,
'onStateChange': onYoutubePlayerStateChange
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment