Skip to content

Instantly share code, notes, and snippets.

@ghorvat
Created November 22, 2015 11:22
Show Gist options
  • Save ghorvat/86ef5690d8bdb752e380 to your computer and use it in GitHub Desktop.
Save ghorvat/86ef5690d8bdb752e380 to your computer and use it in GitHub Desktop.
function equalizeHeights(selector) {
var heights = new Array();
// Loop to get all element heights
jQuery(selector).each(function () {
// Need to let sizes be whatever they want so no overflow on resize
jQuery(this).css('min-height', '0');
jQuery(this).css('max-height', 'none');
jQuery(this).css('height', 'auto');
// Then add size (no units) to array
heights.push(jQuery(this).outerHeight());
});
// Find max height of all elements
var max = Math.max.apply(Math, heights);
console.log(max);
// Set all heights to max height
jQuery(selector).each(function () {
jQuery(this).css('min-height', max + 'px');
var hei = jQuery(this).css('min-height', max + 'px');
var x = jQuery(this).find(".buttonWrapper");
var pos = jQuery(x).position();
var calculation = max - (pos.top + jQuery(x).outerHeight());
jQuery(x).css("margin-top", calculation);
});
}
jQuery(function () {
equalizeHeights("#products-list .item .bg");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment