Skip to content

Instantly share code, notes, and snippets.

@seanwalsh
Created July 30, 2014 20:03
Show Gist options
  • Save seanwalsh/7831f57d902a495c899f to your computer and use it in GitHub Desktop.
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.
<figure class="video">
<iframe id="video-player" data-videoid="du4Y4KtGXBg" src="" frameborder="0" allowfullscreen></iframe>
</figure>
// 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