<style>
* {
padding: 0;
margin: 0;
}
#uls {
width: 500px;
height: 500px;
margin: 50px auto;
}
li {
width: 150px;
height: 150px;
background: skyblue;
float: left;
list-style: none;
margin: 5px;
color: #fff;
text-align: center;
line-height: 150px;
font-size: 20px;
font-weight: bold;
}
#uls li button {
width: 50px;
height: 30px;
}
.light {
width: 150px;
height: 150px;
background: #666;
color: #fff;
}
</style>
<body>
<ul id='uls'>
<li>600元优惠券</li>
<li>800元优惠券</li>
<li>1000元优惠券</li>
<li>800元优惠券</li>
<li><button id='btn1'>开始</button> <button id='btn2'>停止</button></li>
<li>600元优惠券</li>
<li>600元优惠券</li>
<li>1000元优惠券</li>
<li>800元优惠券</li>
</ul>
<script>
let alli = document.querySelectorAll('li')
var btn1 = document.querySelector(" #btn1");
var btn2 = document.querySelector(" #btn2");
let arr = [0, 1, 2, 5, 8, 7, 6, 3]
let num = 0
let cal = ''
alli[0].classList.add('light')
btn1.onclick = function () {
function go() {
btn1.disabled = true;
alli[arr[num]].classList.remove('light')
num++
if (num > arr.length - 1) num = 0
alli[arr[num]].classList.add('light')
}
cal = setInterval(go, 50)
}
btn2.onclick = function () {
btn1.disabled = false;
clearInterval(cal)
}
</script>
</body>