<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style-type: none;
}
.box {
width: 492px;
height: 4px;
border-radius: 10px;
margin: 50px auto;
}
li {
float: left;
width: 160px;
height: 160px;
box-sizing: border-box;
border-radius: 10px;
border: 1px solid #000;
margin-left: 4px;
margin-top: 4px;
font-size: 40px;
padding: 20px;
text-align: center;
line-height: 60px;
box-shadow: 4px 4px 8px 0px #ccc inset,-4px -4px 8px 0px #ccc inset;
}
#btn {
cursor: pointer;
background-color: gold;
color:#fff;
}
.msg {
width: 400px;
height:100px;
border: 10px solid gold;
position: fixed;
cursor: pointer;
top: 50%;
left: 50%;
margin-top: -55px;
margin-left: -205px;
background-color: #fff;
font-size: 88px;
text-align: center;
line-height: 100px;
color: gold;
text-shadow: 0 0 10px #f00;
animation: txt 1s linear infinite;
}
@keyframes txt{
0%,100%{
text-shadow: 0px 0px 4px #f00;
}
50% {
text-shadow: 0px 0px 12px #f0f;
}
}
</style>
</head>
<body>
<div class="box">
<ul>
<li class="item">一等奖</li>
<li class="item">二等奖</li>
<li class="item">三等奖</li>
<li class="item">四等奖</li>
<li id="btn">开始抽奖</li>
<li class="item">五等奖</li>
<li class="item">六等奖</li>
<li class="item">七等奖</li>
<li class="item">谢谢惠顾</li>
</ul>
</div>
<div class="msg">特等奖</div>
</body>
</html>
<script>
var msg = document.querySelectorAll('.msg')[0];
msg.onclick = function () {
console.log(msg === this);
this.style.display = 'none';
};
var btn = document.getElementById('btn');
var items = document.querySelectorAll('.item');
console.log( items );
var itemsNew = [items[0],items[1],items[2],items[4],items[7],items[6],items[5],items[3]];
console.log(itemsNew);
var current = -1;
function choujiang() {
btn.onclick = null;
var cishu = 10 + parseInt(Math.random() * 20);
var timerName = setInterval(function () {
current++;
if( current > itemsNew.length - 1 ){
current = 0;
}
console.log( current );
for(var i=0; i< itemsNew.length; i++ ){
itemsNew[i].style.backgroundColor = '';
}
itemsNew[current].style.backgroundColor = '#ff9d1b';
cishu--;
if(cishu==0){
clearInterval(timerName);
msg.innerText = itemsNew[current].innerText;
msg.style.display = 'block';
btn.onclick = choujiang;
}
},100);
}
btn.onclick = choujiang;
</script>