Created
November 21, 2015 10:51
-
-
Save anikets/626a014411375b3ddaa3 to your computer and use it in GitHub Desktop.
Class for equalizing heights of elements. Works on window resize.
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
// 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