Created
October 7, 2014 22:10
-
-
Save thisislawatts/c21e5637c100e408e90a to your computer and use it in GitHub Desktop.
All items on the same row should have equal heights
This file contains hidden or 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() { | |
/* | |
* http://benhowdle.im/2014/01/29/easy-peasy-equal-heights/ | |
*/ | |
function sameHeights(selector) { | |
var selector = selector || '[data-equal-height]'; | |
query = document.querySelectorAll(selector), | |
elements = query.length, | |
max = 0; | |
rows = {}; | |
if (elements) { | |
while (elements--) { | |
var element = query[elements]; | |
if (element.clientHeight > max) { | |
max = element.clientHeight; | |
} | |
rows[element.offsetTop] = element.clientHeight; | |
} | |
elements = query.length; | |
while (elements--) { | |
var element = query[elements]; | |
element.style.height = rows[element.offsetTop] + 'px'; | |
} | |
} | |
} | |
if ('addEventListener' in window) { | |
window.addEventListener('resize', function(){ | |
sameHeights(); | |
}); | |
window.addEventListener('load', function(){ | |
sameHeights(); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment