Skip to content

Instantly share code, notes, and snippets.

@thisislawatts
Created October 7, 2014 22:10
Show Gist options
  • Save thisislawatts/c21e5637c100e408e90a to your computer and use it in GitHub Desktop.
Save thisislawatts/c21e5637c100e408e90a to your computer and use it in GitHub Desktop.
All items on the same row should have equal heights
(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