Created
December 13, 2013 10:39
-
-
Save driesd/7942542 to your computer and use it in GitHub Desktop.
Make elements equal height
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($){ | |
$.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