Created
June 10, 2014 22:31
-
-
Save LouWii/0f2fce3eadcd0ecd4016 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
/* Get the ID from a youtube link */ | |
function getYoutubeID(url) { | |
var id = url.match("[\\?&]v=([^&#]*)"); | |
id = id[1]; | |
return id; | |
}; | |
/* Get an image preview of the video */ | |
var thumb_url = "http://i3.ytimg.com/vi/"+getYoutubeID('MY-YOUTUBE-VIDEO-URL')+"/maxresdefault.jpg"; | |
$('<img id="video-preview" src="'+thumb_url+'" />').prependTo($("div.preview-video")); | |
/* details about youtube previews there : http://stackoverflow.com/a/2068371/1740412 */ | |
/* Create an iframe to embed the player */ | |
$('<iframe id="youtube-iframe" style="border:0;" src="https://www.youtube.com/embed/'+getYoutubeID('MY-YOUTUBE-VIDEO-URL')+'?autoplay=1&autohide=1&border=0&wmode=opaque&enablejsapi=1" />').prependTo($("div.youtube-embed")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment