Skip to content

Instantly share code, notes, and snippets.

@wyne
Last active December 21, 2015 09:48
Show Gist options
  • Save wyne/6287268 to your computer and use it in GitHub Desktop.
Save wyne/6287268 to your computer and use it in GitHub Desktop.
Equal Heights
// Make all children of this parent the same height
$.fn.eqChildHeights = function() {
var el = $(this);
if (el.length > 0 && !el.data('eqHeights')) {
$(window).bind('resize.eqHeights', function() {
el.eqHeights();
});
el.data('eqHeights', true);
}
return el.each(function() {
var curHighest = 0;
$(this).children().each(function() {
var el = $(this),
elHeight = el.height('auto').height();
if (elHeight > curHighest) {
curHighest = elHeight;
}
}).height(curHighest);
});
};
// Equalize heights of all elements this method is called one
// Ex: $(".column").equalizeHeights();
$.fn.equalizeHeights = function() {
var el = $(this);
// Bind resize event once
if (el.length > 0 && !el.data('equalizeHeights')) {
$(window).bind('resize.equalizeHeights', function() {
el.equalizeHeights();
});
el.data('equalizeHeights', true);
}
// Responsive escape
if ($(window).width() < 768){
return el.height('initial');
}
var curHighest = 0;
el.each(function() {
var el = $(this),
elHeight = el.height('auto').height();
if (elHeight > curHighest) {
curHighest = elHeight;
}
}).height(curHighest);
return el;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment