jquery實現(xiàn)抽獎功能
更新時間:2020年10月22日 16:30:15 作者:maxiaoxin1314
這篇文章主要為大家詳細(xì)介紹了jquery實現(xiàn)抽獎功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了jquery實現(xiàn)抽獎功能的具體代碼,供大家參考,具體內(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ā)抽獎 -->
<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; //記錄移動幾圈
var n = 0; //記錄移動了多少次
var timer = null; //旋轉(zhuǎn)計時器
var priceIndex = (Math.random()*lot.length) | 0; //中獎的下標(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時,布爾值為false,所以要加curIndex==0
if(curIndex || curIndex==0){
lot.filter(".lottery-unit-"+curIndex).removeClass("active")
}
curIndex = nowIndex;
// 如何實現(xiàn)中獎
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("中獎的下標(biāo)",priceIndex)
}
if(nowIndex>=lot.length-1){
nowIndex=-1;
}
}
btn.click(function(){
if(isClick){
console.log("開始抽獎");
isClick = false;
timer = setInterval(move,100);
}
})
</script>
</body>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- jquery.rotate.js實現(xiàn)可選抽獎次數(shù)和中獎內(nèi)容的轉(zhuǎn)盤抽獎代碼
- jquery 年會抽獎程序
- jQuery實現(xiàn)轉(zhuǎn)動隨機(jī)數(shù)抽獎效果的方法
- jquery 抽獎小程序?qū)崿F(xiàn)代碼
- jquery實現(xiàn)九宮格大轉(zhuǎn)盤抽獎
- jQuery實現(xiàn)類似老虎機(jī)滾動抽獎效果
- jquery輸入數(shù)字隨機(jī)抽獎特效的簡單實現(xiàn)代碼
- jquery實現(xiàn)轉(zhuǎn)盤抽獎功能
- jquery——九宮格大轉(zhuǎn)盤抽獎實例
- jQuery+PHP實現(xiàn)的擲色子抽獎游戲?qū)嵗?/a>
相關(guān)文章
jQuery實現(xiàn)鏈接的title快速出現(xiàn)的方法
這篇文章主要介紹了jQuery實現(xiàn)鏈接的title快速出現(xiàn)的方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-02-02
jQuery插件HighCharts實現(xiàn)的2D面積圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts實現(xiàn)的2D面積圖效果,結(jié)合完整實例形式分析了jQuery插件HighCharts繪制2D面積圖的相關(guān)步驟與屬性設(shè)置技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03
jQuery+CSS 實現(xiàn)隨滾動條增減的汽水瓶中的液體效果
一個很有意思的網(wǎng)站,那個網(wǎng)站是一家德國汽水公司的網(wǎng)站(德文神馬的),網(wǎng)站首頁有一個汽水瓶,汽水瓶里的水會隨著我們向下拉滾動條而減少。2011-09-09
jQuery實現(xiàn)的簡單折疊菜單(折疊面板)效果代碼
這篇文章主要介紹了jQuery實現(xiàn)的簡單折疊菜單(折疊面板)效果代碼,涉及jQuery中slideToggle與toggleClass方法的靈活使用技巧,需要的朋友可以參考下2015-09-09

