Last active
August 29, 2015 13:57
-
-
Save jacknycz/9765284 to your computer and use it in GitHub Desktop.
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
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