Skip to content

Instantly share code, notes, and snippets.

@driesd
Created December 13, 2013 10:39
Show Gist options
  • Save driesd/7942542 to your computer and use it in GitHub Desktop.
Save driesd/7942542 to your computer and use it in GitHub Desktop.
Make elements equal height
(function($){
$.fn.equalheights = function(options, settings){
var max = 0,
that = this,
deBouncer = function($,cf,of, interval){
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
}
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || interval);
};
};
jQuery.fn[cf] = function(fn){ return fn ? this.bind(of, debounce(fn)) : this.trigger(cf); };
},
setHeights = function() {
max = 0;
$(that).removeAttr('style');
for(var i=0, j=that.length; i<j; i++) {
max = ($(that[i]).outerHeight() > max) ? $(that[i]).outerHeight() : max;
}
$(that).css('height', max + 'px');
};
// Debounce for frontend performance
deBouncer(jQuery,'smartresize', 'resize', 50);
// Window functions
$(window)
.smartresize(function() {
setHeights();
})
.smartresize()
.load(function () {
setHeights();
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment