Created
March 17, 2020 11:06
-
-
Save wesamly/df0acd7c477a803fd6b9e35f95c99b47 to your computer and use it in GitHub Desktop.
Make adjacent divs same height with Javascript
This file contains 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 resetSameTopElmsHeight(container, childSelector) { | |
var cols, ph, pt, tempElms, i, ch, co, j; | |
cols = container.find(childSelector); | |
ph = -1; | |
pt = -1; | |
tempElms = []; | |
for (i in cols) { | |
ch = $(cols[i]).outerHeight(); | |
co = $(cols[i]).offset(); | |
if (pt != -1 && pt < co.top) { | |
pt = co.top; | |
for (j in tempElms) { | |
$(tempElms[j]).outerHeight(ph) | |
} | |
ph = -1 | |
tempElms = []; | |
} | |
tempElms.push(cols[i]); | |
if (ph < ch) { | |
ph = ch; | |
} | |
pt = co.top; | |
} | |
} | |
//Example: | |
resetSameTopElmsHeight($('.row'), '.col-sm-6'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment