-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
176 lines (154 loc) · 4.63 KB
/
index.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
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
box-sizing: border-box;
}
body,
html {
width: 100%;
height: 100%;
background: #eee;
display: -webkit-box;
display: flex;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: center;
justify-content: center;
}
.lottery {
position: relative;
}
ul {
width: 240px;
height: 240px;
}
.lottery li,
.lottery span {
width: 80px;
height: 80px;
border: 1px solid #000;
text-align: center;
line-height: 80px;
position: absolute;
background: #fff;
font-family: "微软雅黑";
font-size: 1.1em;
}
.lottery>ul li:nth-of-type(1),
.lottery>ul li:nth-of-type(3),
.lottery>ul li:nth-of-type(4),
.lottery>ul li:nth-of-type(8) {
border-bottom: none;
}
.lottery>ul li:nth-of-type(2),
.lottery>ul li:nth-of-type(6) {
border-right: none;
border-left: none;
}
.lottery>ul li:nth-of-type(1) {
left: 0;
top: 0;
}
.lottery>ul li:nth-of-type(2) {
left: 80px;
}
.lottery>ul li:nth-of-type(3) {
left: 160px;
top: 0;
}
.lottery>ul li:nth-of-type(4) {
left: 160px;
top: 80px;
}
.lottery>ul li:nth-of-type(5) {
left: 160px;
top: 160px;
}
.lottery>ul li:nth-of-type(6) {
left: 80px;
top: 160px;
}
.lottery>ul li:nth-of-type(7) {
left: 0;
top: 160px;
}
.lottery>ul li:nth-of-type(8) {
left: 0;
top: 80px;
}
#start {
left: 80px;
top: 80px;
cursor: pointer;
background: rgba(0, 150, 136, 0.5);
border: none;
}
.active:after {
position: absolute;
top: 0;
left: 0;
content: "";
width: 100%;
height: 100%;
background: rgba(0, 150, 136, 0.5)
}
</style>
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="lottery">
<ul>
<li class="lottery-ui">1</li>
<li class="lottery-ui">2</li>
<li class="lottery-ui">3</li>
<li class="lottery-ui">4</li>
<li class="lottery-ui">5</li>
<li class="lottery-ui">6</li>
<li class="lottery-ui">7</li>
<li class="lottery-ui">8</li>
</ul>
<span id="start">开始抽奖</span>
</div>
<script src="./Lottery.js"></script>
<script>
// 抽奖中不可再次点击
var started = false;
function random(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
}
document.getElementById('start').onclick = function () {
if (started) return;
started = true;
new Lottery({
el: '.lottery',
index: 1, //开始位置
total: 5, //转动次数
end: random(1, 7), //结束位置 可换成请求返回的索引
speed: 30, //转动速度
handle(obj) {
started = false;
alert(document.querySelectorAll('.lottery-ui')[obj.end].innerHTML);
}
});
}
</script>
</body>
</html>