Skip to content

Instantly share code, notes, and snippets.

@vaporic
Created June 3, 2017 05:41
Show Gist options
  • Save vaporic/8045725ad9de9749ef4335cc63589a1e to your computer and use it in GitHub Desktop.
Save vaporic/8045725ad9de9749ef4335cc63589a1e to your computer and use it in GitHub Desktop.
visualizar thumbnail de youtube
<iframe width="420" height="315" src="//www.youtube.com/embed/1sIWez9HAbA" frameborder="0" allowfullscreen></iframe>
<div>Click the thumbnail</div>
var iframe = $('iframe:first');
var iframe_src = iframe.attr('src');
var youtube_video_id = iframe_src.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/).pop();
if (youtube_video_id.length == 11) {
var video_thumbnail = $('<img src="//img.youtube.com/vi/'+youtube_video_id+'/0.jpg">');
$('body').append(video_thumbnail);
$('img:first').click(function() {
$('iframe:first').fadeToggle('400');
});
}
div {float:left;margin:20px;}
iframe {display:none;}
img {float:left;width:120px;height:90px;cursor:pointer;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment