Skip to content

Instantly share code, notes, and snippets.

@lackneets
Last active August 9, 2016 02:29
Show Gist options
  • Save lackneets/b81b11b234997057b73e72e28aa0f414 to your computer and use it in GitHub Desktop.
Save lackneets/b81b11b234997057b73e72e28aa0f414 to your computer and use it in GitHub Desktop.
Make youtube iframe responsive
$(function(){
$('iframe[src*="youtube"][width][height]').each(function(){
var w = $(this).attr('width');
var h = $(this).attr('height');
$(this).wrap($('<div class="youtube-wrapper">').css({
'max-width' : '100%',
'height': 0,
'padding-bottom': (h/w*100) + '%',
'position': 'relative'
})).css({
'position': 'absolute',
'top': 0, 'right': 0, 'bottom': 0, 'left': 0,
'width': '100%', 'height': '100%', 'margin': 0
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment