Skip to content

Instantly share code, notes, and snippets.

@anikets
Created November 21, 2015 10:51
Show Gist options
  • Save anikets/626a014411375b3ddaa3 to your computer and use it in GitHub Desktop.
Save anikets/626a014411375b3ddaa3 to your computer and use it in GitHub Desktop.
Class for equalizing heights of elements. Works on window resize.
// Class for equalizing heights of elements. Works on window resize.
// Example usage:
// var instanceObject = Object.create(equalizeHeightsWithResize);
// instanceObject.selector = '.srp-prod h3';
// instanceObject.eq();
var equalizeHeightsWithResize = {
max: 0,
rt: null,
selector: '',
eq: function() {
// console.log(this.selector);
that = this;
$(this.selector).each(function(i, v) {
// console.log(parseInt($(this).height()), 'max:', that.max);
if (parseInt($(this).height()) > that.max) {
that.max = parseInt($(this).height());
$(that.selector).css('min-height', that.max + 'px');
}
});
$(window).resize(function() {
clearTimeout(that.rt);
setTimeout(function() {
// console.log('that.selector', that.selector);
$(that.selector).css('min-height', that.max + 'px');
}, 200);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment