jquery實(shí)現(xiàn)抽獎(jiǎng)功能
本文實(shí)例為大家分享了jquery實(shí)現(xiàn)抽獎(jiǎng)功能的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> #lottery { width: 570px; height: 510px; margin: 0px auto; border: 4px solid #ba1809; } #lottery table { background-color: yellow; } #lottery table td { position: relative; width: 190px; height: 170px; text-align: center; color: #333; font-index: -999 } #lottery table td img { display: block; width: 190px; height: 170px; } #lottery table td a { width: 190px; height: 170px; display: block; text-decoration: none; background: url(img/9.jpg) no-repeat top center; } #lottery table td a:hover { background-image: url(img/11.jpg); } #lottery table td.active .mask { display: block; } .mask { width: 100%; height: 100%; position: absolute; left: 0; top: 0; background-color: rgba(252, 211, 4, 0.5); display: none; } </style> </head> <body> <div id="lottery"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td class="lottery-unit lottery-unit-0"> <img src="img/1.jpg"> <div class="mask"></div> </td> <td class="lottery-unit lottery-unit-1"> <img src="img/2.jpg"> <div class="mask"></div> </td> <td class="lottery-unit lottery-unit-2"> <img src="img/3.jpg"> <div class="mask"></div> </td> </tr> <tr> <td class="lottery-unit lottery-unit-7"> <img src="img/4.jpg"> <div class="mask"></div> </td> <!-- 點(diǎn)擊觸發(fā)抽獎(jiǎng) --> <td><a href="#" rel="external nofollow" ></a></td> <td class="lottery-unit lottery-unit-3"> <img src="img/5.jpg"> <div class="mask"></div> </td> </tr> <tr> <td class="lottery-unit lottery-unit-6"> <img src="img/6.jpg"> <div class="mask"></div> </td> <td class="lottery-unit lottery-unit-5"> <img src="img/7.jpg"> <div class="mask"></div> </td> <td class="lottery-unit lottery-unit-4"> <img src="img/8.jpg"> <div class="mask"></div> </td> </tr> </table> </div> <script src="js/jquery.js"></script> <script type="text/javascript"> var lot = $(".lottery-unit"); var nowIndex = -1; //記錄添加激活類的下標(biāo) var btn = $("table").find("a") console.log(btn) var curIndex = null; //記錄上一次坐標(biāo) var round = 0; //記錄移動(dòng)幾圈 var n = 0; //記錄移動(dòng)了多少次 var timer = null; //旋轉(zhuǎn)計(jì)時(shí)器 var priceIndex = (Math.random()*lot.length) | 0; //中獎(jiǎng)的下標(biāo) console.log(priceIndex) var isClick = true; function move(){ n++; nowIndex++; if(n%8==0){ round++; console.log("跑了"+round+"圈"); if(round>=3){ clearInterval(timer); timer = setInterval(move,50) } if(round > 8){ clearInterval(timer); timer = setInterval(move,1000) } } // 第二種方式 // if(n>=8 && n<12){ // clearInterval(timer) // timer = setInterval(move,50) // } // if(n>=12){ // clearInterval(timer) // timer = setInterval(move,50) // } lot.filter(".lottery-unit-"+nowIndex).addClass("active") // 當(dāng)curIndex為0時(shí),布爾值為false,所以要加curIndex==0 if(curIndex || curIndex==0){ lot.filter(".lottery-unit-"+curIndex).removeClass("active") } curIndex = nowIndex; // 如何實(shí)現(xiàn)中獎(jiǎng) if(nowIndex == priceIndex && round > 8){ clearInterval(timer); if(priceIndex==1){ setTimeout(function(){ alert("111111") },1000) } // 重置參數(shù) isClick = true; round = 0; nowIndex = -1; curIndex = null; priceIndex = (Math.random()*lot.length) | 0; console.log("中獎(jiǎng)的下標(biāo)",priceIndex) } if(nowIndex>=lot.length-1){ nowIndex=-1; } } btn.click(function(){ if(isClick){ console.log("開始抽獎(jiǎng)"); isClick = false; timer = setInterval(move,100); } }) </script> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jquery.rotate.js實(shí)現(xiàn)可選抽獎(jiǎng)次數(shù)和中獎(jiǎng)內(nèi)容的轉(zhuǎn)盤抽獎(jiǎng)代碼
- jquery 年會(huì)抽獎(jiǎng)程序
- jQuery實(shí)現(xiàn)轉(zhuǎn)動(dòng)隨機(jī)數(shù)抽獎(jiǎng)效果的方法
- jquery 抽獎(jiǎng)小程序?qū)崿F(xiàn)代碼
- jquery實(shí)現(xiàn)九宮格大轉(zhuǎn)盤抽獎(jiǎng)
- jQuery實(shí)現(xiàn)類似老虎機(jī)滾動(dòng)抽獎(jiǎng)效果
- jquery輸入數(shù)字隨機(jī)抽獎(jiǎng)特效的簡單實(shí)現(xiàn)代碼
- jquery實(shí)現(xiàn)轉(zhuǎn)盤抽獎(jiǎng)功能
- jquery——九宮格大轉(zhuǎn)盤抽獎(jiǎng)實(shí)例
- jQuery+PHP實(shí)現(xiàn)的擲色子抽獎(jiǎng)游戲?qū)嵗?/a>
相關(guān)文章
使用jquery實(shí)現(xiàn)圖文切換效果另加特效
白天活干完,弄個(gè)jquery仿凡客誠品圖片切換的效果;以前寫的不是很好,今天重新做個(gè)jquery特效,其實(shí)很簡單,感興趣的朋友可以了解下哦,希望本文對你有幫助2013-01-01AMD異步模塊定義介紹和Require.js中使用jQuery及jQuery插件的方法
這篇文章主要介紹了AMD異步模塊定義介紹和Require.js中使用jQuery及jQuery插件的方法,需要的朋友可以參考下2014-06-06jQuery EasyUI tree 使用拖拽時(shí)遇到的錯(cuò)誤小結(jié)
在我使用tree拖拽時(shí)總是失敗,控制臺(tái)輸出了很多錯(cuò)誤。經(jīng)過問題跟蹤分析最終找到的錯(cuò)誤原因,下面小編給大家分享下,感興趣的朋友參考下2016-10-10使用element-ui的el-menu導(dǎo)航選中后刷新頁面保持當(dāng)前選中狀態(tài)
這篇文章主要介紹了使用element-ui的el-menu導(dǎo)航選中后刷新頁面保持當(dāng)前選中狀態(tài),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07基于jquery的9行js輕松實(shí)現(xiàn)tab控件示例
tab控件的實(shí)現(xiàn)方法有很多,在本文為大家詳細(xì)介紹下如何通過9行js實(shí)現(xiàn)簡單的tab控件,感興趣的朋友不要錯(cuò)過2013-10-10jQuery中closest和parents的區(qū)別分析
本文給大家介紹jquery中parents()和closest()用法與區(qū)別介紹,在jquery中parents()查找父級(jí)元素刪除的時(shí)候,發(fā)現(xiàn)它不包含根元素,于是用了closest(),效果不錯(cuò),下面我來給大家具體的介紹一下2015-05-05Tab頁界面,用jQuery及Ajax技術(shù)實(shí)現(xiàn)
從桌面開發(fā)的時(shí)代開始,Tab頁就是一個(gè)優(yōu)異的界面布局形式,兼有菜單的樣式和充分復(fù)用有限的界面的優(yōu)點(diǎn)。2009-09-09