Skip to content

Instantly share code, notes, and snippets.

@livercake
Created August 6, 2014 15:48
Show Gist options
  • Save livercake/428009fc59420ae88ef0 to your computer and use it in GitHub Desktop.
Save livercake/428009fc59420ae88ef0 to your computer and use it in GitHub Desktop.
Video embeds: Aspect ratio fluid resizer
$(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