Last active
August 9, 2016 02:29
-
-
Save lackneets/b81b11b234997057b73e72e28aa0f414 to your computer and use it in GitHub Desktop.
Make youtube iframe responsive
This file contains hidden or 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
$(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