Created
December 18, 2017 19:21
-
-
Save joseadrian/40e81148700cffb65e73e972e50cf841 to your computer and use it in GitHub Desktop.
Rsponsive Youtube Embed
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
iframe[attribute*=youtube] { | |
width: 100%; | |
} | |
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 $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