Skip to content

Instantly share code, notes, and snippets.

@ethanclevenger91
Last active August 29, 2015 14:10
Show Gist options
  • Save ethanclevenger91/94f0abc4f2527a13ce94 to your computer and use it in GitHub Desktop.
Save ethanclevenger91/94f0abc4f2527a13ce94 to your computer and use it in GitHub Desktop.
jQuery match height plugin
(function ( $ ) { //inline jQuery plugin to match height of elements
$.fn.match_height = function(userOptions, callback) {
var defaults = {
mode:'maximum'
};
var options = $.extend({}, defaults, userOptions);
if(options.mode == 'maximum') {
var height=0;
} else {
var height = this.first().height();
}
this.each(function() {
if(options.mode == 'maximum') {
if($(this).height() > height) {
height = $(this).height();
}
} else if(options.mode == 'minimum') {
if($(this).height() < height) {
height = $(this).height();
}
}
});
this.each(function() {
$(this).height(height);
});
if(typeof callback == 'function') {
callback.call(this);
}
return height;
};
}( jQuery ));
//match the height of all cols in rows (bootstrap)
$('.row').each(function() {
$(this).find('div[class^="col-"]').match_height();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment