Created
July 30, 2014 20:03
-
-
Save seanwalsh/7831f57d902a495c899f to your computer and use it in GitHub Desktop.
HTML & simple jQuery to display and autoplay a YouTube video after a button/link has been clicked. There is more magic that displays the content but that is for another gist. This just sets the URL of the iframe and starts the video.
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
<figure class="video"> | |
<iframe id="video-player" data-videoid="du4Y4KtGXBg" src="" frameborder="0" allowfullscreen></iframe> | |
</figure> |
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
// Display the video | |
var youtubeID = $('#video-player').data('videoid'); // get the video id from the data-attribute | |
var youtubeURL = "//www.youtube.com/embed/" + youtubeID + "?autoplay=1"; // build the url | |
$('#video-player').attr('src', youtubeURL); // set the url | |
$("figure.video").fitVids(); // Use FitVids to size the videos. (http://fitvidsjs.com/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment