Skip to content

Instantly share code, notes, and snippets.

@jacknycz
Last active August 29, 2015 13:57
Show Gist options
  • Save jacknycz/9765284 to your computer and use it in GitHub Desktop.
Save jacknycz/9765284 to your computer and use it in GitHub Desktop.
function sameHeights(selector) {
var selector = selector || '[data-key="sameHeights"]',
query = document.querySelectorAll(selector),
elements = query.length,
max = 0;
if (elements) {
while (elements--) {
var element = query[elements];
if (element.clientHeight > max) {
max = element.clientHeight;
}
}
elements = query.length;
while (elements--) {
var element = query[elements];
element.style.height = max + 'px';
}
}
}
if ('addEventListener' in window) {
window.addEventListener('onresize', function(){
sameHeights();
});
window.addEventListener('load', function(){
sameHeights();
});
}
// Add the following to any div/element that you want to be the same size
data-key="sameHeights"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment