点击开始按钮开始抽奖,div依次变红!下面是js代码,需要的自取
<script>
var but1 = document.getElementById("btn1")
var but2 = document.getElementById("btn2")
var alldiv = document.querySelectorAll(".father>div")
console.log(alldiv);
var index = 0;
var flag = 0;
but1.onclick=function(){
if(flag == 0)
{
t = setInterval(()=>{
index= index>=(alldiv.length-1)?0:++index;
alldiv[index].style.backgroundColor = "gold";
if(index !=0){
alldiv[index-1].style.backgroundColor = "#fff";
}else if(index==0){
alldiv[19].style.backgroundColor = "#fff";
}
// alldiv[index].style.backgroundColor = "red";
console.log(index)
},1)
flag = 1;
}
but2.onclick=function(){
clearInterval(t);
flag = 0;
}
}
</script>
下面是html,css代码
style>
.father{
width: 600px;
height: 600px;
/* border: 1px solid darkorchid; */