Created
February 13, 2015 14:47
-
-
Save tvaliasek/89ea74071bf132f50e7c to your computer and use it in GitHub Desktop.
jQuery fix for same height items in row
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
/* | |
* example of html structure: | |
* | |
* <div class="row row-same-height"> | |
* <div class="col-sm-6 col-xs-12"> | |
* <div class="same-height-item">...</div> | |
* </div> | |
* <div class="col-sm-6 col-xs-12"> | |
* <div class="same-height-item">...</div> | |
* </div> | |
* </div> | |
*/ | |
jQuery(function(){ | |
var $fixTimeout; | |
$(window).resize(function(){ | |
clearTimeout($fixTimeout); | |
$fixTimeout = setTimeout(changeElsMinHeight(), 170); | |
}); | |
function changeElsMinHeight(){ | |
var $rows = $('.row-same-height'); | |
$rows.each(function(){ | |
var $els = $(this).find('.same-height-item'); | |
var $minHeight = 0; | |
$els.css('min-height', $minHeight+'px'); | |
$els.each(function(){ | |
if($(this).outerHeight(false)>$minHeight){ | |
$minHeight = $(this).outerHeight(false); | |
} | |
}); | |
$minHeight+=12; | |
$els.css('min-height', $minHeight+'px'); | |
}); | |
} | |
changeElsMinHeight(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment