Created
November 2, 2010 14:31
-
-
Save bjrn/659684 to your computer and use it in GitHub Desktop.
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
/* | |
jQuery.equalHeights Plugin | |
@author John Hunter | |
@dependency jQuery 1.4.x | |
EqualHeights version 2.0 (2010-09-07 johnhunter.info) | |
Based on an idea copyright (c) 2008 Rob Glazebrook (cssnewbie.com) | |
use: $('#selector').equalHeights({minHeight: 200}); | |
see defaults object for options | |
*/ | |
(function($) { | |
var defaults = { | |
minHeight: 0, | |
maxHeight: 0, | |
overflow: 'auto', | |
useMinHeight: true, | |
eachCallback: null | |
}; | |
$.fn.equalHeights = function (options) { | |
var tallest, | |
ohOpts = { margin: true }, | |
heights = this.outerHeights({ margin: true }); | |
options = $.extend({}, defaults, options); | |
heights.push(options.minHeight); | |
tallest = Math.max.apply(null, heights); | |
if(options.maxHeight && tallest > maxHeight) tallest = maxHeight; | |
return this.each(function(i) { | |
var el = $(this), | |
of = options.overflow, | |
cb = options.eachCallback, | |
property = (!options.useMinHeight || (/MSIE 6/.test(navigator.userAgent))) ? 'height' : 'min-height', | |
height = tallest + el.height() - el.outerHeight(ohOpts); | |
el.css(property, height); | |
if (of) el.css('overflow', of); | |
if ($.isFunction(cb)) cb.call(this, i, el, height); | |
}); | |
}; | |
$.fn.outerHeights = function (opts) { | |
return $.map(this, function (i) { | |
return $(i).outerHeight(opts); | |
}); | |
}; | |
})(jQuery); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment