Skip to content

Instantly share code, notes, and snippets.

@joseadrian
Created December 18, 2017 19:21
Show Gist options
  • Save joseadrian/40e81148700cffb65e73e972e50cf841 to your computer and use it in GitHub Desktop.
Save joseadrian/40e81148700cffb65e73e972e50cf841 to your computer and use it in GitHub Desktop.
Rsponsive Youtube Embed
iframe[attribute*=youtube] {
width: 100%;
}
var $allVideos = $("iframe[src*='.youtube.com']").each(function() {
$(this).data('aspectRatio', this.height / this.width).removeAttr('height').removeAttr('width');
});
$(window).resize(function() {
$allVideos.each(function() {
var $el = $(this);
$el.height($el.width() * $el.data('aspectRatio'));
});
}).resize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment