Last active
September 9, 2015 16:02
-
-
Save afalchi82/86e74aa424eff386f1ad to your computer and use it in GitHub Desktop.
Set same height for a collection of elements
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 () { | |
var fn = { | |
sameHeightCols: function () { | |
var throttled = _.throttle(init, 100); | |
function init() { | |
$('.row').each(function (i, e) { | |
var items = $('[class*="col-"]', e); | |
//Reset height | |
items.css('height', 'auto'); | |
var maxH = (function () { | |
var h = 0; | |
for (var i = 0; i < items.length; i++) { | |
$(items[i]).height() > h ? h = $(items[i]).height() : null; | |
} | |
return h; | |
}()); | |
items.css('height', maxH + 'px'); | |
console.log('New height: ', maxH); | |
}); | |
} | |
$(window).resize(throttled).resize(); | |
} | |
}; | |
/*-------------------------------------------------- | |
Doc ready | |
--------------------------------------------------*/ | |
$(function () { | |
fn.sameHeightCols(); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment