Skip to content

@johnhunter /jQuery.equalHeights.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
jQuery plugin that ensures html elements share the same height
/*
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
Something went wrong with that request. Please try again.