Created
August 14, 2012 02:28
-
-
Save mpezzi/3345824 to your computer and use it in GitHub Desktop.
jQuery Equal Heights
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 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