Skip to content

Instantly share code, notes, and snippets.

@michaelrog
Created March 31, 2013 18:37
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 michaelrog/5281552 to your computer and use it in GitHub Desktop.
Save michaelrog/5281552 to your computer and use it in GitHub Desktop.
jQuery width/height equalizer fn
/*--------------------------------------------------------------------
* jQuery equalizer
* by Michael Rog
*
* based on the JQuery Plugins "EqualHeights" & "EqualWidths"
* by Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
*--------------------------------------------------------------------*/
$.fn.equalizeHeights = function() {
var currentMax = 0;
$(this).each(function(i){
window.log("equalizeHeights: comparing: " + $(this).height() + " vs " + currentMax);
if ($(this).height() > currentMax) { currentMax = $(this).height(); }
});
window.log("equalizeHeights: max height for this set is " + currentMax);
// for ie6, set height since min-height isn't supported
if ($.browser.msie && $.browser.version == 6.0) { $(this).css({'height': currentMax}); }
$(this).css({'min-height': currentMax}).addClass("equalizer_HeightsEqualized");
return this;
};
$.fn.equalizeWidths = function() {
var currentMax = 0;
$(this).each(function(i){
window.log("equalizeWidths: comparing: " + $(this).width() + " vs " + currentMax);
if ($(this).width() > currentMax) { currentMax = $(this).width(); }
});
window.log("equalizeWidths: max width for this set is " + currentMax);
// for ie6, set width since min-width isn't supported
if ($.browser.msie && $.browser.version == 6.0) { $(this).css({'width': currentMax}); }
$(this).css({'min-width': currentMax}).addClass("equalizer_WidthsEqualized");
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment