var files = [], slide='', str='';
for (let n = 0; n < 28; n++) {
files[n]=n+1;
}
var len=files.length-1,endlen = files.length>32 ? files.length-32 : 0;
var i=0;
while (len>=endlen) {
str+=`<li>${files[len]}</li>`;
i++;
if(i%8==0 || len==endlen){
slide+=`<ul>${str}</ul>`;
str='';
}
len--;
}
$('body').append(slide)
每8个为一组,最多共4组,倒序排列。
正序循环分组
var files = [];
var slide = '', str = '';
for (let n = 0; n < 12; n++) {
files[n]=n+1;
}
for (var i = 0; i < files.length; i++) {
str += `<li data-index="${i}">${files[i]}</li>`;
if ((i+1) % 5 == 0 || i == files.length-1) {
slide += `<ul>${str}</ul>`;
str = '';
}
}
$('body').append(slide)
Comments | NOTHING