Skip to content

Instantly share code, notes, and snippets.

@mpezzi
Created August 14, 2012 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpezzi/3345824 to your computer and use it in GitHub Desktop.
Save mpezzi/3345824 to your computer and use it in GitHub Desktop.
jQuery Equal Heights
/**
* jQuery Equal Height Plugin by M. Pezzi
* Version: 1.0-alpha (08/13/12)
* Dual licensed under the MIT and GPL licences:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires: jQuery v1.4.2 or later
*/
(function($) {
$.fn.equal_height = function() {
var self = $(this), max_height = 0;
// Determine max height when document is resized.
$(window).resize(function(){
self
.each(function(){
$(this)
.css('min-height', '')
.css('height', 'auto');
if ( $(this).height() > max_height ) {
max_height = $(this).height();
}
})
.each(function(){
$(this).css('min-height', max_height + 'px');
})
// @TODO: Find a better way to reset max_height when loops are finished.
.each(function(){
max_height = 0;
});
});
// When window is completely loaded (including images), trigger equal heights.
$(window).load(function(){
$(window).trigger('resize');
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment