Last active
August 29, 2015 14:10
-
-
Save ethanclevenger91/94f0abc4f2527a13ce94 to your computer and use it in GitHub Desktop.
jQuery match height plugin
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
(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