Last active
August 29, 2015 14:13
-
-
Save felix-d/ad6ac4a8cebda897e7c5 to your computer and use it in GitHub Desktop.
Function for jquery to set divs to the same height, using the max height of those divs.
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
//Author: Felix Descoteaux | |
//Usage: $.sameheight($("#element1"), $(".element2"), ... ); | |
(function($) { | |
var sameHeight = function sameHeight() { | |
var arrayOfHeights = [], | |
arr = Array.prototype.slice.call(arguments), | |
max; | |
//Clear any height value | |
arr.forEach(function(e) { | |
e.height(""); | |
}); | |
//Push outerHeight in array | |
arr.forEach(function(e) { | |
arrayOfHeights.push(e.outerHeight()); | |
}); | |
//Set max | |
max = Math.max.apply(null, arrayOfHeights); | |
//Set css | |
arr.forEach(function(entry) { | |
entry.css({ | |
position: "relative", | |
height: max | |
}); | |
}); | |
}; | |
//Set function | |
$.sameHeight = sameHeight; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment