Document<br>.list {<br> margin: 50px auto;<br> padding: 0;<br> list-style-type: none;<br> width: 300px;<br> position: relative;<br>} <br>.list li {<br> position: absolute;<br> border: 1px solid #000;<br> width: 98px;<br> height: 98px;<br> text-align: center;<br> line-height: 98px;<br> font-size: 20px;<br>}<br>.list li:nth-of-type(1){<br> left: 0;<br> top: 0;<br>}<br>.list li:nth-of-type(2){<br> left: 100px;<br> top: 0;<br>}<br>.list li:nth-of-type(3){<br> left: 200px;<br> top: 0;<br>}<br>.list li:nth-of-type(4){<br> left: 200px;<br> top: 100px;<br>}<br>.list li:nth-of-type(5){<br> left: 100px;<br> top: 100px;<br>}<br>.list li:nth-of-type(6){<br> left: 200px;<br> top: 200px;<br>}<br>.list li:nth-of-type(7){<br> left: 100px;<br> top: 200px;<br>}<br>.list li:nth-of-type(8){<br> left: 0px;<br> top: 200px;<br>}<br>.list li:nth-of-type(9){<br> left: 0px;<br> top: 100px;<br>}<br>.list span {<br> display: block;<br> height: 100%;<br> background: #ccc;<br>}<br>.list .show {<br> background: #f60;<br> color: #fff;<br>}<br><br>window.onload = function(){<br> var spans = document.querySelectorAll('span');<br> var a = document.querySelector('a');<br> var nub = 5;<br> var timer = 0;<br> a.onclick = function(){<br> var target = [0,1,5,2,7];<br> var length = (Math.round(Math.random()*4) + 2)*spans.length+1+target[Math.floor(Math.random()*target.length)];<br> var arr = [];<br> var now = 0;<br> var delay = 50;<br> console.log(length);<br> for(var i = 0; i < length; i++){<br/> arr.push(i);<br/> }<br/> setShow();<br/> function setShow(){<br/> timer = setTimeout(function(){<br/> for(var i = 0; i < spans.length; i++){<br/> spans[i].className = "";<br/> }<br/> spans[arr[now]%spans.length].className = "show";<br/> now++;<br/> //递归终止条件<br/> if(now < arr.length){<br/> delay += 10;<br/> setShow();<br/> }<br/> },delay);<br/> }<br/> };<br/>}; <br/> 三等奖 谢谢惠顾 三等奖 二等奖 开始抽奖 一等奖 谢谢惠顾 二等奖 三等奖