Last active
August 29, 2015 14:06
-
-
Save krambuhl/52dd890f58498c87d744 to your computer and use it in GitHub Desktop.
EqualHeights Class
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
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