/** * jQuery.AspectRatio plugin * * Copyright (c) 2008 Steven Rogers (http://www.therogerdodger.com/) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ jQuery.fn.AspectRatio = function() { var imgR = (this.height() / this.width()); var containerR = (this.offsetParent().outerHeight() / this.offsetParent().outerWidth()); if (imgR > containerR) this.height(this.offsetParent().outerHeight()); else this.width(this.offsetParent().outerWidth()); return this; };