Created
July 29, 2014 21:28
-
-
Save aradnom/512becc133c0253608d3 to your computer and use it in GitHub Desktop.
YouTube API example wrapping existing iframe elements.
This file contains hidden or 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
/* Youtube */ | |
window.onYouTubeIframeAPIReady = function () { | |
window.youtube_players = []; | |
$('.video_container.youtube').each( function () { | |
// Only set the play functionality up if the video has a thumbnail | |
if ( $(this).find('.video_thumbnail').length ) { | |
var thumbnail = $(this).find('.video_thumbnail'), | |
play = $(this).find('.video_play'), | |
player = new YT.Player( $(this).children('iframe').attr('id') ); | |
window.youtube_players.push( player ); | |
var thumbnail_height = thumbnail.find('img').height(); | |
$(this).height(thumbnail_height); | |
// Play button | |
play.click( function () { | |
player.playVideo(); | |
thumbnail.fadeTo( 200, 0, function () { | |
thumbnail.css( 'z-index', 0 ); | |
}); | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment