JS 抽奖机
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> *{ margin: 0; padding: 0; } .box{ width: 300px; margin: 100px auto; } .up{ } .up div,.center div,.button div{ box-sizing: border-box; border: 1px solid red; width: 100px; height: 100px; text-align: center; line-height: 100px; float: left; } .start{ cursor: pointer; background-color: #FF6600; color: white; } ul{ width: 300px; height: 300px; border: 1px solid red; } li{ width: 80px; height: 80px; } </style> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> </head> <body> <div class="box"> <h2 align="center">嘉靖翻牌子</h2> <div class="up"> <div class="opcation">谢谢参与</div> <div class="opcation">美女一枚</div> <div class="opcation">帅哥一枚</div> </div> <div class="center"> <div class="opcation">游乐场游玩</div> <div class="start">开始抽奖</div> <div class="opcation">iphoneX</div> </div> <div class="button"> <div class="opcation">华晨宝马</div> <div class="opcation">奥迪a3</div> <div class="opcation">奔驰G1</div> </div> </div> </body> <script type="text/javascript"> $(function(){ $(".start").click(function(){ let spend = 0 let num = null let timer = null //定义一个0-8的随机数 //开启一个定时器 clearInterval(timer) timer = setInterval(()=>{ spend = spend + 1 num = Math.round(Math.random()*7) $(".opcation").each(function(k,v){ $(".opcation")[k].style.background = "white" }) $(".opcation")[num].style.background = "red" if(spend >= 20){ clearInterval(timer) setTimeout(()=>{ let str = $(".opcation")[num].innerText alert("恭喜您获得"+str) },400) } },100) }) }) </script> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构