周末总得学点什么吧~
奥利给!
- 跑火车 递归 减速
let currentIndex = 0;
let speed = 500; // 初始速度,单位是毫秒
let decrement = 20; // 每次迭代速度减少的量
const cells = document.querySelectorAll('.cell');
function highlightCell() {
cells.forEach((cell, index) => {
cell.classList.remove('highlight');
if (index === currentIndex) {
cell.classList.add('highlight');
}
});
if (speed > 50) {
// 当速度降低到一定程度时停止
speed -= decrement;
setTimeout(highlightCell, speed);
currentIndex = (currentIndex + 1) % cells.length; // 移动到下一个格子
}
}
highlightCell(<