-
-
Save nocodesupplyco/96183490d2b30f052cd89ad5f9e044f2 to your computer and use it in GitHub Desktop.
Set Equal Heights Based on Tallest
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
// 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