Created
August 3, 2015 14:32
-
-
Save clemgrim/33b2bfd1a05ac6608882 to your computer and use it in GitHub Desktop.
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
// layout for only 2 columns | |
function layout (container, selector) { | |
var ct = container.jquery ? container : $(container); | |
var themes = ct.find(selector); | |
var colLeft = 0; | |
var colRight = 0; | |
// resize and position `.theme` elements | |
themes.each (function (idx) { | |
var elm = $(this); | |
var height = elm.outerHeight(); | |
var deltaLeft = colLeft + height; | |
var deltaRight = colRight + height; | |
var isLeft; | |
// Determine on which column put the current element | |
if (deltaRight === deltaLeft) { | |
isLeft = idx%2 === 0; | |
} else { | |
isLeft = deltaRight > deltaLeft; | |
} | |
elm.css({ | |
position: 'absolute', | |
left: isLeft ? 0 : elm.outerWidth(), | |
top: isLeft ? colLeft : colRight, | |
}); | |
// increment columns height | |
isLeft ? colLeft += height : colRight += height; | |
}); | |
// apply height to the parent | |
ct.height(Math.max(colLeft, colRight)); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment