<div id="box" class="box">
<div class="outer KinerLottery KinerLotteryContent"><img src="./imgs/lotteryContent.png"></div>
<!-- 大專盤分為三種狀態(tài):活動未開始(no-start)、活動進(jìn)行中(start)、活動結(jié)束(completed),可通過切換class進(jìn)行切換狀態(tài),js會根據(jù)這3個class進(jìn)行匹配狀態(tài) -->
<div class="inner KinerLotteryBtn start"></div>
</div>
js部分
/**
* 根據(jù)轉(zhuǎn)盤旋轉(zhuǎn)角度判斷獲得什么獎品
* @param deg
* @returns {*}
*/
var whichAward = function(deg) {
if ((deg > 330 && deg <= 360) || (deg > 0 && deg <= 30)) { //10M流量
return "三網(wǎng)通流量 10M";
} else if ((deg > 30 && deg <= 90)) { //IPhone 7
return "iPhone7";
} else if (deg > 90 && deg <= 150) { //30M流量
return "三網(wǎng)通流量 30M";
} else if (deg > 150 && deg <= 210) { //5元話費(fèi)
return "話費(fèi)5元";
} else if (deg > 210 && deg <= 270) { //IPad mini 4
return "ipad mini4";
} else if (deg > 270 && deg <= 330) { //20元話費(fèi)
return "話費(fèi)20元";
}
}
var KinerLottery = new KinerLottery({
rotateNum: 8,
//轉(zhuǎn)盤轉(zhuǎn)動圈數(shù)
body: "#box",
//大轉(zhuǎn)盤整體的選擇符或zepto對象
direction: 0,
//0為順時針轉(zhuǎn)動,1為逆時針轉(zhuǎn)動
disabledHandler: function(key) {
switch (key) {
case "noStart":
alert("活動尚未開始");
break;
case "completed":
alert("活動已結(jié)束");
break;
}
},
//禁止抽獎時回調(diào)
clickCallback: function() {
//此處訪問接口獲取獎品
function random() {
return Math.floor(Math.random() * 360);
}
this.goKinerLottery(random());
},
//點(diǎn)擊抽獎按鈕,再次回調(diào)中實(shí)現(xiàn)訪問后臺獲取抽獎結(jié)果,拿到抽獎結(jié)果后顯示抽獎畫面
KinerLotteryHandler: function(deg) {
alert("恭喜您獲得:" + whichAward(deg));
} //抽獎結(jié)束回調(diào)
});
css部分:
html {
font-size : 20px;
}
@media only screen and (min-width: 401px){
html {
font-size: 25px !important;
}
}
@media only screen and (min-width: 428px){
html {
font-size: 26.75px !important;
}
}
@media only screen and (min-width: 481px){
html {
font-size: 30px !important;
}
}
@media only screen and (min-width: 569px){
html {
font-size: 35px !important;
}
}
@media only screen and (min-width: 641px){
html {
font-size: 40px !important;
}
}
html, body {
padding: 0;
margin: 0;
background: #fffeea;
height: 100%;
}
p,li,b,span,div,strong,h1,h2,h3,h4,h5,h6,a,ul{
margin: 0;
padding: 0;
text-decoration: none;
list-style: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.box {
width: 14rem;
height: 14rem;
position: relative;
margin: 0 auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
-webkit-transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
-o-transform: translate(-50%,-50%);
}
.box .outer {
width: 100%;
height: 100%;
position: absolute;
z-index: 1;
top: 0;
left: 0;
transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
}
.box .outer img{
width: 100%;
}
.box .inner{
position: relative;
width: 5rem;
height: 5rem;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
z-index: 2;
background-image: url(../imgs/lotteryBtn.png);
background-size: auto 5rem;
background-repeat: no-repeat;
}
.box .inner.start:active{
-webkit-transform: translate(-50%, -50%) scale(.95);
-moz-transform: translate(-50%, -50%) scale(.95);
-ms-transform: translate(-50%, -50%) scale(.95);
-o-transform: translate(-50%, -50%) scale(.95);
transform: translate(-50%, -50%) scale(.95);
}
.box .inner.start{
background-position: 0 0;
}
.box .inner.no-start{
background-position: -5rem 0;
}
.box .inner.completed{
background-position: -10rem 0;
}