摘要:需求抽獎(jiǎng)代碼最多可以抽獎(jiǎng)次,而且,每次只會(huì)中元理財(cái)金或者謝謝參與,其它的不會(huì)抽中哈哈,果然都是套路。
需求:
抽獎(jiǎng)代碼最多可以抽獎(jiǎng)5次,而且,每次只會(huì)中“2000元理財(cái)金”或者“謝謝參與”,其它的不會(huì)抽中(哈哈,果然都是套路)。
效果如下:
一、頁(yè)面結(jié)構(gòu):
?1 2 3 4 5 6 7 8 9 10 11 12 |
|
標(biāo)簽h2為提示內(nèi)容,.playnum是剩余抽獎(jiǎng)次數(shù),.g-lottery-img是最外層的閃燈,.g-lottery-img是轉(zhuǎn)動(dòng)的內(nèi)容,.playbtn是點(diǎn)擊抽獎(jiǎng)按鈕。
這里用的是jquery.rotate.js,所以要引入jquery然后引入jquery.rotate.js,百度一下很簡(jiǎn)單的,沒(méi)幾個(gè)AIP。
二、簡(jiǎn)單的樣式:
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
.g-content {
width: 100%;
background: #fbe3cc;
height: auto;
font-family: "微軟雅黑" , "microsoft yahei" ;
}
.g-content .g-lottery- case {
width: 500px;
margin: 0 auto;
overflow: hidden;
}
.g-content .g-lottery- case .g-left h2 {
font-size: 20px;
line-height: 32px;
font-weight: normal;
margin-left: 20px;
}
.g-content .g-lottery- case .g-left {
width: 450px;
float: left;
}
.g-lottery-box {
width: 400px;
height: 400px;
margin-left: 30px;
position: relative;
background: url(ly-plate-c.gif) no-repeat;
}
.g-lottery-box .g-lottery-img {
width: 340px;
height: 340px;
position: relative;
background: url(bg-lottery.png) no-repeat;
left: 30px;
top: 30px;
}
.g-lottery-box .playbtn {
width: 186px;
height: 186px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -94px;
margin-top: -94px;
background: url(playbtn.png) no-repeat;
}
|
樣式就定一下高度,居中一下,顯示一下背景圖片
三、JS代碼:
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
$( function () {
var $btn = $( .g-lottery-img ); // 旋轉(zhuǎn)的div
var playnum = 5; //初始次數(shù),由后臺(tái)傳入
$( .playnum ).html(playnum); //顯示還剩下多少次抽獎(jiǎng)機(jī)會(huì)
var isture = 0; //是否正在抽獎(jiǎng)
var clickfunc = function () {
var data = [1, 2, 3, 4, 5, 6]; //抽獎(jiǎng)
//data為隨機(jī)出來(lái)的結(jié)果,根據(jù)概率后的結(jié)果
data = data[Math.floor(Math.random() * data.length)]; //1~6的隨機(jī)數(shù)
switch (data) {
case 1:
rotateFunc(1, 0, 恭喜您獲得2000元理財(cái)金 );
break ;
case 2:
rotateFunc(2, 0, 恭喜您獲得2000元理財(cái)金2 );
break ;
case 3:
rotateFunc(3, 0, 恭喜您獲得2000元理財(cái)金3 );
break ;
case 4:
rotateFunc(4, -60, 謝謝參與4 );
break ;
case 5:
rotateFunc(5, 120, 謝謝參與5 );
break ;
case 6:
rotateFunc(6, 120, 謝謝參與6 );
break ;
}
}
$( ".playbtn" ).click( function () {
if (isture) return ; // 如果在執(zhí)行就退出
isture = true ; // 標(biāo)志為 在執(zhí)行
if (playnum <= 0) { //當(dāng)抽獎(jiǎng)次數(shù)為0的時(shí)候執(zhí)行
alert( "沒(méi)有次數(shù)了" );
$( .playnum ).html(0); //次數(shù)顯示為0
isture = false ;
} else { //還有次數(shù)就執(zhí)行
playnum = playnum - 1; //執(zhí)行轉(zhuǎn)盤了則次數(shù)減1
if (playnum <= 0) {
playnum = 0;
}
$( .playnum ).html(playnum);
clickfunc();
}
});
var rotateFunc = function (awards, angle, text) {
isture = true ;
$btn.stopRotate();
$btn.rotate({
angle: 0, //旋轉(zhuǎn)的角度數(shù)
duration: 4000, //旋轉(zhuǎn)時(shí)間
animateTo: angle + 1440, //給定的角度,讓它根據(jù)得出來(lái)的結(jié)果加上1440度旋轉(zhuǎn)
callback: function () {
isture = false ; // 標(biāo)志為 執(zhí)行完畢
alert(text);
}
});
};
});
|
說(shuō)到底就是用一個(gè)1~6的隨機(jī)數(shù),然后把對(duì)應(yīng)的角度值傳給jquery.rotate.js,它就會(huì)轉(zhuǎn)到相應(yīng)的地方,最后做一下對(duì)應(yīng)剩余次數(shù)的判斷和修改。
最后所有代碼為:
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
所需要的圖片(這里好像上傳不了壓縮文件,所以不能整個(gè)打包上傳了):
#復(fù)制下面的圖片名稱-鼠標(biāo)移到圖片上-右鍵-圖片另存為-粘貼保存#
1.最外面的閃燈:ly-plate-c.gif
2.六個(gè)中獎(jiǎng)內(nèi)容:bg-lottery.png
3.點(diǎn)擊抽獎(jiǎng)按鈕: playbtn.png
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/1066.html
摘要:圓盤抽獎(jiǎng)應(yīng)用頁(yè)面圓盤抽獎(jiǎng)應(yīng)用演示抱歉瀏覽器不支持。 HTML5 Canvas圓盤抽獎(jiǎng)應(yīng)用DEMO html頁(yè)面 HTML5 Canvas圓盤抽獎(jiǎng)應(yīng)用DEMO演示 抱歉!瀏覽器不支持。 抱歉!瀏覽器不支持。 抱歉!瀏覽器...
摘要:圓盤抽獎(jiǎng)應(yīng)用頁(yè)面圓盤抽獎(jiǎng)應(yīng)用演示抱歉瀏覽器不支持。 HTML5 Canvas圓盤抽獎(jiǎng)應(yīng)用DEMO html頁(yè)面 HTML5 Canvas圓盤抽獎(jiǎng)應(yīng)用DEMO演示 抱歉!瀏覽器不支持。 抱歉!瀏覽器不支持。 抱歉!瀏覽器...
摘要:圓盤抽獎(jiǎng)應(yīng)用頁(yè)面圓盤抽獎(jiǎng)應(yīng)用演示抱歉瀏覽器不支持。 HTML5 Canvas圓盤抽獎(jiǎng)應(yīng)用DEMO html頁(yè)面 HTML5 Canvas圓盤抽獎(jiǎng)應(yīng)用DEMO演示 抱歉!瀏覽器不支持。 抱歉!瀏覽器不支持。 抱歉!瀏覽器...
摘要:根據(jù)產(chǎn)品提出的需求,需要做一個(gè)抽獎(jiǎng)活動(dòng)頁(yè)面需求簡(jiǎn)介九宮格抽獎(jiǎng),中獎(jiǎng)概率可配置,以九宮格轉(zhuǎn)盤的形式進(jìn)行抽獎(jiǎng),獎(jiǎng)品分為三類,實(shí)物類獎(jiǎng)品,收貨人信息可編輯,默認(rèn)為登陸用戶,可生成訂單福幣類獎(jiǎng)品,直接發(fā)放,可在交易明細(xì)中查看優(yōu)惠劵類獎(jiǎng)品,交易明細(xì)中 根據(jù)產(chǎn)品提出的需求,需要做一個(gè)抽獎(jiǎng)活動(dòng)頁(yè)面 需求簡(jiǎn)介 九宮格抽獎(jiǎng),中獎(jiǎng)概率可配置,以九宮格轉(zhuǎn)盤的形式進(jìn)行抽獎(jiǎng),獎(jiǎng)品分為三類, 實(shí)物類獎(jiǎng)品,收貨人...
閱讀 769·2023-04-25 19:43
閱讀 4022·2021-11-30 14:52
閱讀 3855·2021-11-30 14:52
閱讀 3909·2021-11-29 11:00
閱讀 3838·2021-11-29 11:00
閱讀 3949·2021-11-29 11:00
閱讀 3613·2021-11-29 11:00
閱讀 6310·2021-11-29 11:00