I know this question has been asked a million times but i'm looking for something more specific.
As my site is fully responsive I need the divs to be resized based on a per row basis rather than setting all to one height.
I am using the following modified code to set the heights of all divs within a container:
$.fn.eqHeights = function() {
var el = $(this);
if (el.length > 0 && !el.data('eqHeights')) {
$(window).bind('resize.eqHeights', function() {
el.eqHeights();
});
el.data('eqHeights', true);
}
return el.each(function() {
var curTop = 0;
var curHighest = 0;
$(this).children().each(function(indx) {
var el = $(this),
elHeight = el.height('auto').outerHeight();
var thisTop = el.position().top;
if (curTop > 0 && curTop != thisTop) {
curHighest = 0;
}
if (elHeight > curHighest) {
curHighest = elHeight;
}
curTop = thisTop;
}).height(curHighest);
});
};
I have var thisTop = el.position().top;
to determine which elements are on the same row but am unsure how I can then set all elements in the same row to the highest value?
Currently .height(curHighest);
sets all the elements to the same height whether they are on the same row or not.
Thanks for help with this.
I recently had to do the same thing, this is what I ended up with:
Here's a fiddle
Managed to get this working with the following snippet:
I also added the ability to specify a certain element so that this gets the height change instead.
Usage:
I took dclawson's excellent answer and made some edits so it works in other situations, particularly with nested elements as is commen in bootstrap rows.
It works with the same syntax