Created
July 1, 2017 09:56
-
-
Save dakshhmehta/e91e21beaaa3c99e5fd24165eea86342 to your computer and use it in GitHub Desktop.
Fixes the heights of all children to same one.
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
/** | |
Usage: | |
<div class="row same-height" data-class="col-md-4"> | |
<div class="col-md-4"><p></p></div> | |
<div class="col-md-4"><p></p><p></p></div> | |
<div class="col-md-4"><p></p></div> | |
<div class="col-md-4"><p></p></div> | |
</div> | |
All columns will have height similar to second column as It has highest height amount all of them. | |
**/ | |
var max_height = 0; | |
$(".same-height").each(function(){ | |
var className = $(this).data('class'); | |
if(className){ | |
$(this).children('.'+className).each(function(){ | |
if(max_height < $(this).height()){ | |
max_height = $(this).height(); | |
} | |
}); | |
} | |
if(className){ | |
$(this).children('.'+className).each(function(){ | |
$(this).height(max_height); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment