Created
March 27, 2015 11:26
-
-
Save itpcc/1a570e7cc4417b16329c to your computer and use it in GitHub Desktop.
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
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