Skip to content

Instantly share code, notes, and snippets.

@pygeek
Created July 3, 2012 16:52
Show Gist options
  • Save pygeek/3040973 to your computer and use it in GitHub Desktop.
Save pygeek/3040973 to your computer and use it in GitHub Desktop.
Maintains aspect ratio of widescreen video. change 'video' to be the tag, class, id, or combination of the three for element.
$(function(){
var el = $('video'),
maintain_aspect = function(){
el.each(function(){
var $width = $(this).innerWidth(),
$new_height = $width * .562;
$(this).css({'height' : $new_height})
})
};
$(window).resize(function(){
maintain_aspect()
})
// on page load
maintain_aspect()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment