Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created December 19, 2022 15:25
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 nocodesupplyco/96183490d2b30f052cd89ad5f9e044f2 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/96183490d2b30f052cd89ad5f9e044f2 to your computer and use it in GitHub Desktop.
Set Equal Heights Based on Tallest
// Add the attribute of data-match-height="groupName" to all elements you want to match height
var matchHeight = function () {
function init() {
eventListeners();
matchHeight();
}
function eventListeners(){
$(window).on('resize', function() {
matchHeight();
});
}
function matchHeight(){
var groupName = $('[data-match-height]');
var groupHeights = [];
groupName.css('min-height', 'auto');
groupName.each(function() {
groupHeights.push($(this).outerHeight());
});
var maxHeight = Math.max.apply(null, groupHeights);
groupName.css('min-height', maxHeight);
};
return {
init: init
};
} ();
$(function() {
matchHeight.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment