Skip to content

Instantly share code, notes, and snippets.

@afalchi82
Last active September 9, 2015 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afalchi82/86e74aa424eff386f1ad to your computer and use it in GitHub Desktop.
Save afalchi82/86e74aa424eff386f1ad to your computer and use it in GitHub Desktop.
Set same height for a collection of elements
(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