Created
August 6, 2014 15:48
-
-
Save livercake/428009fc59420ae88ef0 to your computer and use it in GitHub Desktop.
Video embeds: Aspect ratio fluid resizer
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() { | |
$allVideos = $(".video iframe, .video object, .video embed"); | |
$fluidEl = $("div.video"); | |
$allVideos.each(function() { | |
$(this).attr('data-aspectRatio', this.height / this.width) | |
.removeAttr('height') | |
.removeAttr('width'); | |
}); | |
$(window).resize(function() { | |
var newWidth = $fluidEl.width(); | |
$allVideos.each(function() { | |
var $el = $(this); | |
$el.width(newWidth).height(newWidth * $el.attr('data-aspectRatio')); | |
}); | |
}).resize(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment