Skip to content

Instantly share code, notes, and snippets.

@pygeek
Created October 3, 2012 07:04
Show Gist options
  • Save pygeek/3825494 to your computer and use it in GitHub Desktop.
Save pygeek/3825494 to your computer and use it in GitHub Desktop.
Maintains aspect ratio as (jQuery plugin)
$.fn.maintainAspect = function(cb){
var el = this,
_maintain_aspect = function(el){
var $width = el.parent().width();
var $height = $width / 2.39;
el.attr('width', $width)
el.attr('height', $height)
//trigger callback
cb()
};
// initialize
_maintain_aspect(el)
$(window).resize(function(){
_maintain_aspect(el)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment