Skip to content

Instantly share code, notes, and snippets.

@pygeek
Last active December 18, 2015 04:29
Show Gist options
  • Save pygeek/5725385 to your computer and use it in GitHub Desktop.
Save pygeek/5725385 to your computer and use it in GitHub Desktop.
Make certain elements uniform height.
$(function(){
var uniform_el_height = {
'parent_el' : '.row#management-services_row-6451 .container', //common immediate parent of elements to make uniform height
'el' : '> .block', //element to make uniform height
'resize_els' : function(initial_offset){
var $max_height = 0;
var self = this;
$(self.parent_el).children().each(function(){
var $this_el = $(this).find(self.el);
//reset height of block
$this_el.css({'height' : ''})
//initialize height of block
var $height = 0;
//calculate height of combined children manually
$this_el.children().each(function(){
//outerHeight(true) for actual height of content with margin
$height += $(this).outerHeight(true)
})
//update max_height
if ($height > $max_height){
$max_height = $height;
}
})
//apply new height
$(self.parent_el).children().each(function(){
var $this_el = $(this).find(self.el);
$this_el.height($max_height + initial_offset)
})
},
'init' : function(){
var self = this;
$(window).resize(function(){
self.resize_els(0)
})
//bug for instance I was working on makes initial height of blocks
//50px more than what they need to be, but upon resizing window,
//it corrects itself. Allowing an initial_offset argument was a quick fix for
//this issue; needs further investigating.
self.resize_els(-50)
}
}
uniform_el_height.init()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment