Skip to content

Instantly share code, notes, and snippets.

@krambuhl
Last active August 29, 2015 14:06
Show Gist options
  • Save krambuhl/52dd890f58498c87d744 to your computer and use it in GitHub Desktop.
Save krambuhl/52dd890f58498c87d744 to your computer and use it in GitHub Desktop.
EqualHeights Class
var EqualHeights = (function($, _) {
function EqualHeights (el, opts) {
this.options = _.extend({ item: '.equal-item' }, opts);
this.items = $(el).find(this.options.item);
$(window).on('resize', _.bind(this.resize, this)).trigger('resize');
}
EqualHeights.prototype.resize = function() {
this.items.height(getMaxHeight(this.items));
};
function getMaxHeight(items) {
return _.max(items.map(function() {
return getItemHeight(this);
}).get());
}
function getItemHeight(item) {
return _.reduce($(item).children().map(function() {
return $(this).outerHeight(true);
}).get(), function(memo, h) {
memo += h;
return memo;
}, 0);
}
return EqualHeights;
}).call(this, jQuery, _);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment