Last active
December 22, 2015 16:38
-
-
Save xposedbones/6500167 to your computer and use it in GitHub Desktop.
Set every item (or their child) to the same height easily (needs jquery)
This file contains 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
;(function($){ | |
$.fn.setHeight = function(affectChildren){ | |
if (typeof affectChildren === "undefined" || affectChildren===null) affectChildren = false; | |
var height = []; | |
this.each(function(){ | |
if(affectChildren){ | |
height = []; | |
$(this).children().each(function(){ | |
height.push($(this).outerHeight()); | |
}); | |
$(this).children().css("min-height",Math.max.apply(null,height)); | |
}else{ | |
height.push($(this).outerHeight()); | |
} | |
}); | |
if(!affectChildren){ | |
this.css("min-height",Math.max.apply(null,height)); | |
} | |
}; | |
// USAGE - Use both if you have webfonts, otherwise, just use $(TARGET).setHeight(); | |
// $(window).load(function(){ | |
// $(".auto-height").setHeight(true); | |
// }); | |
// | |
// $(".auto-height").setHeight(true); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment