Skip to content

Instantly share code, notes, and snippets.

@omgmog
Created May 13, 2012 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omgmog/2690184 to your computer and use it in GitHub Desktop.
Save omgmog/2690184 to your computer and use it in GitHub Desktop.
jQuery snippet for embedding YouTube videos with custom thumbnails
$(function(){
$('.ytembed:not(.processed)').addClass('processed').each(function() {
$(this).find('a').click(function(e) {
e.preventDefault();
var width = $(this).find('img').width();
var height = $(this).find('img').height();
var url = $(this).attr('href');
var $iframe = $('<iframe src="'+url+'" width="'+width+'" height="'+height+'" frameborder="0"/>');
$(this).parent().html($iframe);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment