Skip to content

Instantly share code, notes, and snippets.

@Uriel29
Forked from uzielweb/equal_heights_grouped.js
Created September 15, 2016 00:40
Show Gist options
  • Save Uriel29/cdb568dd3d62f5bf277b7d940230c027 to your computer and use it in GitHub Desktop.
Save Uriel29/cdb568dd3d62f5bf277b7d940230c027 to your computer and use it in GitHub Desktop.
This is a Script to autoresize DIVS grouped to each parente div to set the same heights
<script type="text/javascript">
jQuery(document).ready(function($){
/* Thanks to CSS Tricks for pointing out this bit of jQuery
http://css-tricks.com/equal-height-blocks-in-rows/
It's been modified into a function called at page load and then each time the page is resized. One large modification was to remove the set height before each new calculation. */
equalheight = function(container){
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(container).each(function() {
$el = $(this);
$($el).height('auto')
topPostion = $el.position().top;
if (currentRowStart != topPostion) {
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
rowDivs.length = 0; // empty the array
currentRowStart = topPostion;
currentTallest = $el.height();
rowDivs.push($el);
}
else {
rowDivs.push($el);
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
}
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
});
}
// set function on load page
$(window).load(function() {
// set each parent div
$('.newsitem_text,.categories-list,.row.vdivide,.row.vdividers').each(function(){
// set eachh child div to be resized to same size
equalheight('.col-lg-4.top-module,.col-md-4,.col-lg-4,.item,.top-module-x,.col-sm-4');
});
});
// set function on resize page
$(window).resize(function(){
// set each parent div
$('.newsitem_text,.categories-list,.row.vdivide,.row.vdividers').each(function(){
// set each child div to be resized to same size
equalheight('.col-lg-4.top-module,.col-md-4,.col-lg-4,.item,.top-module-x,.col-sm-4');
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment