Created
July 9, 2012 18:42
-
-
Save dennishall/3078153 to your computer and use it in GitHub Desktop.
Simple columnize javascript function
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 columnize(ul){ | |
var offsetTop = YAHOO.util.Dom.getRegion(ul).top; | |
var listItems = ul.getElementsByTagName('li'); | |
for(var i=0,l=listItems.length;i<l;i++){ | |
var region = YAHOO.util.Dom.getRegion(listItems[i]); | |
if(region.bottom - offsetTop > 200){ | |
var clone = ul.cloneNode(true); | |
// remove all list items that follow this one from the current list. (will be covered by the clone) | |
for(var j=l-1; j>=i; j--){ | |
ul.removeChild( ul.lastChild ); | |
} | |
// remove all list items that precede this one from the clone. (are covered by the original list) | |
for(var j=i; j>0; j--){ | |
clone.removeChild(clone.firstChild); | |
} | |
ul.parentNode.appendChild(clone); | |
// recurse - check whether the clone also needs to be columnized (if it's too tall) | |
columnize(clone); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment