js代码:
let n = 4;
for (let i = 0; i < 9; i++) {
document.body.innerHTML += `<div>${i}</div>`;
let divs = document.querySelectorAll('div');
if (i < 5) {
divs[i].style.left = i * 100 + 'px';
} else {
n--;
divs[i].style.left = i * 100 + 'px';
divs[i].style.top = -(i - n) * 100 + 'px';
}
}