Created
August 26, 2014 11:58
-
-
Save Bellfalasch/74950873ff08426c611e to your computer and use it in GitHub Desktop.
equalHeightAdjacents - make objects in a two column list equal height horizontally
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
function equalHeightAdjacents( elems ) { | |
// Make Tema cards equal height per row so we don't get holes when using float | |
var odd = true; | |
var cardleft = 0; | |
var cardright = 0; | |
var cardleft_h = 0; | |
var cardright_h = 0; | |
$(elems).each( function() { | |
if (odd) { | |
cardleft = $(this); | |
cardleft_h = cardleft.outerHeight(false); | |
odd = false; | |
} else { | |
cardright = $(this); | |
cardright_h = cardright.outerHeight(false); | |
odd = true; | |
} | |
// console.log( odd + ' ' + cardleft_h + ' ' + cardright_h ); | |
if ( cardleft_h > 0 && cardright_h > 0 ) { | |
if ( cardleft_h > cardright_h ) { | |
// Cardleft högst | |
cardright.css('height', cardleft_h + 'px'); | |
cardleft.css('height', cardleft_h + 'px'); // safeing | |
} else { | |
// Cardright högst | |
cardleft.css('height', cardright_h + 'px'); | |
cardright.css('height', cardright_h + 'px'); // safeing | |
} | |
cardleft_h = 0; | |
cardright_h = 0; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment