Created
March 10, 2014 03:53
-
-
Save jmaddington/9459207 to your computer and use it in GitHub Desktop.
Equal Columns
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
/*Keeps columns equal height*/ | |
//Modified from http://www.cssnewbie.com/equal-height-columns-with-jquery/#.UtX2EJ5dXTc | |
function equalHeight(group) { | |
group.each(function(){ | |
$(this).css('height', 'auto'); | |
}) | |
if ($(document).width() > 600) { | |
var tallest = 0; | |
group.each(function() { | |
var thisHeight = $(this).height(); | |
if(thisHeight > tallest) { | |
tallest = thisHeight; | |
} | |
}); | |
group.css('height', tallest + 'px'); | |
} else { | |
group.each(function(){ | |
$(this).css('height', 'auto'); | |
}) | |
} | |
} | |
//Use like this: | |
$(document).ready(function(){ | |
/*Keeps columns on homepage equal height*/ | |
equalHeight($('.columns1')); | |
equalHeight($('.columns2')); | |
$(window).resize(function(){equalHeight($('.columns1'));}); | |
$(window).resize(function(){equalHeight($('.columns2'));}); | |
}); | |
/* HTML is like: | |
<div class='columns1'>stuff...</div> | |
<div class='columns1'>stuff...</div> | |
<br /> | |
<div class='columns2'>stuff...</div> | |
<div class='columns2'>stuff...</div> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment