一个简易的抽奖大转盘

代码如下

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Price Draw</title>
<style>
table{
border:1px solid black;
}
td{
border:1px solid black;
width:50px;
height:50px;
}
a{
text-decoration:none;
color:black;
}
</style>
<script>
var id = 0;
function start(){
var tds = document.getElementsByTagName("td");
for(var idx = 0; idx < tds.length; idx ++){
var mya = tds[idx];
mya.style.backgroundColor = "red";
}

var time = Math.ceil(Math.random()*24+20);
var stop;
var index = 0;
id = 0;
var preId = 1;
stop = setInterval(function(){
index++;
id++;
var pretd = document.getElementById(preId+"");
pretd.style.backgroundColor = "white";
var td = document.getElementById(id+"");
td.style.backgroundColor = "yellow";
preId = id;
if(id>=8){
id = 0;
}

if(index>=time){
clearInterval(stop);
}

},100);
}
</script>
</head>
<body>
<table id="table">
<tr>
<td id="1">50</td>
<td id="2">100</td>
<td id="3">150</td>
</tr>
<tr>
<td id="8">200</td>
<td><a href="#" onclick="start();return false;">开始</a></td>
<td id="4">300</td>
</tr>
<tr>
<td id="7">350</td>
<td id="6">400</td>
<td id="5">500</td>
</tr>
</table>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42218986/article/details/80431731