答案 0 :(得分:0)
评论中的解释。
$(function(){
// function to add content vertically
function addVertically(div, content){
// max blocks per column
maxBlocksPerCol = 10;
//determine which column to add to
col = null;
div.children("div").each(function(){
if($(this).children("div").length < maxBlocksPerCol)
col = $(this);
});
if(col == null){
col = $("<div class='column'></div>");
div.append(col);
}
// finally, append the content to the appropriate div
col.append(content);
}
// the div to add your columns to
div = $("#columns");
// some sample content for each added div
content = "<div class='block'></div>";
// test, adds 15 blocks vertically
columnsToAdd = 15; while(columnsToAdd--) addVertically(div, content);
});