-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlottery.html
334 lines (323 loc) · 15.3 KB
/
lottery.html
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="no"/>
<meta name="wap-font-scale" content="no">
<meta content="telephone=no" name="format-detection">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>滚滚筹-抽奖</title>
<link rel="stylesheet" href="css/swiper.min.css">
<link rel="stylesheet" href="css/common.min.css">
<link rel="stylesheet" href="css/base.min.css">
<link rel="stylesheet" href="css/user.min.css">
</head>
<body class="isHide">
<div class="wrap height top">
<div class="header">
<div class="left">
<a href="javascript:;">
<i class="sprite icon-back"></i>
</a>
</div>
<div class="mid">
<label class="text"><span>幸运大转盘</span></label>
</div>
</div>
<div class="wrap height overflow">
<div class="lottery-box">
<label class="integral">可用积分:<em>5000</em></label>
<div class="container">
<div class="p-rel">
<div class="lottery">
<div class="bg">
<div class="fb-box-list" id="lottery">
<ul class="row-3">
<li>
<div class="award-box award-box-0">
<label><img src="img/lottery/award1.png"></label>
</div>
</li>
<li>
<div class="award-box award-box-1">
<label><img src="img/lottery/award4.png"></label>
</div>
</li>
<li>
<div class="award-box award-box-2">
<label><img src="img/lottery/award3.png"></label>
</div>
</li>
</ul>
<ul class="row-3">
<li>
<div class="award-box award-box-7">
<label><img src="img/lottery/award3.png"></label>
</div>
</li>
<li>
<div class="award-box background">
<a id="lotteryBtn" href="javascript:;"><img
src="img/lottery/lottery-btn.png"></a>
</div>
</li>
<li>
<div class="award-box award-box-3">
<label><img src="img/lottery/award1.png"></label>
</div>
</li>
</ul>
<ul class="row-3">
<li>
<div class="award-box award-box-6">
<label><img src="img/lottery/award2.png"></label>
</div>
</li>
<li>
<div class="award-box award-box-5">
<label><img src="img/lottery/award5.png"></label>
</div>
</li>
<li>
<div class="award-box award-box-4">
<label><img src="img/lottery/award6.png"></label>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="shadow">
<label><img src="img/lottery/lottery-shadow.png"></label>
</div>
<div class="gold">
<label class="left"><img src="img/lottery/lottery-matter2.png"></label>
<label class="right"><img src="img/lottery/lottery-matter3.png"></label>
</div>
</div>
<div class="intro">
<p>抽奖说明:</p>
<label>
<span>1、每10积分可以进行一次抽奖;</span>
<span>2、最终解释权归本公司所有;</span>
</label>
</div>
<div class="list">
<label class="title"><img src="img/lottery/lottery-list-line.png"></label>
<div class="cont">
<label><span>中奖名单</span></label>
<div class="cont-height">
<ul id="winListContainer">
<li class="background">
<span class="user">135****5548</span>
<span>获得</span>
<span class="ticket">1.5%增益券</span>
<span class="time">2017/11/12</span>
</li>
<li>
<span class="user">135****5548</span>
<span>获得</span>
<span class="ticket">1.5%增益券</span>
<span class="time">2017/11/12</span>
</li>
<li class="background">
<span class="user">135****5548</span>
<span>获得</span>
<span class="ticket">1.5%增益券</span>
<span class="time">2017/11/12</span>
</li>
<li>
<span class="user">135****5548</span>
<span>获得</span>
<span class="ticket">1.5%增益券</span>
<span class="time">2017/11/12</span>
</li>
<li class="background">
<span class="user">135****5548</span>
<span>获得</span>
<span class="ticket">1.5%增益券</span>
<span class="time">2017/11/12</span>
</li>
<li>
<span class="user">135****5548</span>
<span>获得</span>
<span class="ticket">1.5%增益券</span>
<span class="time">2017/11/12</span>
</li>
<li class="background">
<span class="user">135****5548</span>
<span>获得</span>
<span class="ticket">1.5%增益券</span>
<span class="time">2017/11/12</span>
</li>
<li>
<span class="user">135****5548</span>
<span>获得</span>
<span class="ticket">1.5%增益券</span>
<span class="time">2017/11/12</span>
</li>
</ul>
</div>
</div>
<div class="bg"></div>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/box.js"></script>
<script src="js/common.js"></script>
<script src="js/base.js"></script>
<script>
$(function () {
//滚动
var _clearTimer_ = 0;
var marqueeText = function (tag, slideDir, time) {
clearInterval(_clearTimer_);
_clearTimer_ = setInterval(function () {
var _top = parseInt($(tag).css("marginTop"));
var _moveHeight = $(tag).find("li:eq(0)").height();
switch (slideDir) {
case "top":
$(tag).animate({
"marginTop": _top - _moveHeight + "px"
}, 300, function () {
$(tag).css({"marginTop": 0}).children("li").last().after($(tag).children("li").first());
});
break;
}
}, time);
};
//中奖信息滚动
marqueeText("#winListContainer", "top", 2000);
//奖品信息
var award = [
{text: "10积分", num: 10, index: 1},
{text: "1.25%增益券", num: 125 / 100, index: 2},
{text: "100积分", num: 100, index: 3},
{text: "10积分", num: 10, index: 4},
{text: "再接再厉", num: 0, index: 5},
{text: "2.25%增益券", num: 225 / 100, index: 6},
{text: "88积分", num: 88, index: 7},
{text: "100积分", num: 100, index: 8}
];
//抽奖代码
var lottery = {
index: -1, //当前转动到哪个位置,起点位置
count: 0, //总共有多少个位置
timer: 0, //setTimeout的ID,用clearTimeout清除
speed: 20, //初始转动速度
times: 0, //转动次数
cycle: 50, //转动基本次数:即至少需要转动多少次再进入抽奖环节
prize: -1, //中奖位置
init: function (id) {
if ($(id).find('.award-box').length > 0) {
var $lottery = $(id);
var $units = $lottery.find('.award-box').not(".background");
this.obj = $lottery;
this.count = $units.length;
$lottery.find('.award-box.award-box-' + this.index).addClass('active');
}
},
roll: function () {
var index = this.index;
var count = this.count;
var lottery = this.obj;
$(lottery).find('.award-box.award-box-' + index).removeClass('active');
index += 1;
if (index > count - 1) {
index = 0;
}
$(lottery).find('.award-box.award-box-' + index).addClass('active');
this.index = index;
return false;
},
stop: function (index) {
this.prize = index;
return false;
}
};
function roll() {
lottery.times += 1;
lottery.roll(); //转动过程调用的是lottery的roll方法,这里是第一次调用初始化
if (lottery.times > lottery.cycle + 10 && lottery.prize == lottery.index) {
clearTimeout(lottery.timer);
var lottery_num = lottery.prize;
var lottery_text = award[lottery.prize].text;
var html = "";
if (lottery_num == 4) {
html = lotteryHtml(false, null);
} else {
html = lotteryHtml(true, lottery_text);
}
setTimeout(function () {
$(document.body).append(html);
$("#lotteryClose").click(function () {
$(".disk-lottery").fadeOut(300, function () {
$(this).remove();
});
});
}, 1000);
lottery.prize = -1;
lottery.times = 0;
click = false;
} else {
if (lottery.times < lottery.cycle) {
lottery.speed -= 10;
} else if (lottery.times == lottery.cycle) {
lottery.prize = Math.random() * (lottery.count) | 0; //静态演示,随机产生一个奖品序号,实际需请求接口产生
} else {
if (lottery.times > lottery.cycle + 10 && ((lottery.prize == 0 && lottery.index == 7) || lottery.prize == lottery.index + 1)) {
lottery.speed += 110;
} else {
lottery.speed += 20;
}
}
if (lottery.speed < 40) {
lottery.speed = 40;
}
lottery.timer = setTimeout(roll, lottery.speed); //循环调用
}
return false;
}
function lotteryHtml(type, lotteryText) {
var img = type ? "img/lottery/pop-lottery-s.png" : "img/lottery/pop-lottery-e.png";
var text = type ? "恭喜你!" : "很遗憾";
var lottery_text = type ? "获得<em>" + lotteryText + "</em>,奖励已放入<br>您的账户中。" : "你没有获得任何奖励!";
var btnText = type ? "立即领取" : "继续抽奖";
var btnID = type ? "successBtn" : "errorBtn";
return '\
<div class="disk-lottery">\
<div class="pop-lottery">\
<div class="cont">\
<div class="close"><a id="lotteryClose" href="javascript:;">×</a></div>\
<div class="title"><label><img src=' + img + '></label></div>\
<div class="text">\
<label>' + text + '</label>\
<span>' + lottery_text + '</span>\
</div>\
<a class="btn" href="javascript:;" id=' + btnID + '>' + btnText + '</a>\
</div>\
</div>\
</div>\
';
}
lottery.init('#lottery');
var click = false;
$("#lotteryBtn").click(function () {
if (click) { //click控制一次抽奖过程中不能重复点击抽奖按钮,后面的点击不响应
return false;
} else {
lottery.speed = 100;
roll(); //转圈过程不响应click事件,会将click置为false
click = true; //一次抽奖完成后,设置click为true,可继续抽奖
return false;
}
});
})
</script>
</body>
</html>