Created
April 12, 2016 15:10
-
-
Save kodie/2e977ca86357a15ab4f8fd7cf75ae70e to your computer and use it in GitHub Desktop.
Make YouTube video embeds responsive
This file contains 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
var responsiveVideos = $('iframe[src*="//www.youtube.com"]'); | |
responsiveVideos.each(function(){ | |
$(this) | |
.data('aspectRatio', $(this).height() / $(this).width()) | |
.width('100%') | |
.removeAttr('height'); | |
}); | |
$(window).resize(function(){ | |
responsiveVideos.each(function(){ | |
$(this) | |
.height($(this).width() * $(this).data('aspectRatio')); | |
}); | |
}).resize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment