尝试下面的代码:(只需更改 min_items_per_col )
$(function($) {
var num_cols = 0,
container = $('.counter-list'),
listItem = 'li',
listClass = 'sub-list';
container.each(function() {
var items_per_col = new Array(),
items = $(this).find(listItem),
min_items_per_col = 15,//Math.floor(items.length / num_cols),
num_cols = Math.ceil((items.length) / min_items_per_col),
difference = items.length - (min_items_per_col * num_cols);
for (var i = 0; i < num_cols; i++) {
if (i < difference) {
items_per_col[i] = min_items_per_col + 1;
} else {
items_per_col[i] = min_items_per_col;
}
}
for (var i = 0; i < num_cols; i++) {
$(this).append($('<ul ></ul>').addClass(listClass));
for (var j = 0; j < items_per_col[i]; j++) {
var pointer = 0;
for (var k = 0; k < i; k++) {
pointer += items_per_col[k];
}
$(this).find('.' + listClass).last().append(items[j + pointer]);
}
}
});
});
.counter-list ul{
float: left;
list-style:none;
border-bottom: 1px solid;
}
.counter-list li{
line-height: 1.5em;
counter-increment: step-counter;
}
.counter-list li:before {
content: counter(step-counter);
margin-right: 5px;
font-size: 80%;
background-color: rgb(0,200,200);
color: white;
font-weight: bold;
padding: 3px 8px;
border-radius: 3px;
}
吃鸡游戏
莫回无
相关分类