forked from fouber/lottery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
254 lines (252 loc) · 8.91 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
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
<!DOCTYPE html>
<html>
<head>
<meta name="screen-orientation" content="portrait">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"/>
<title>年会抽奖小程序</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/wall.css">
<style type="text/css">
body, html {
width: 100%;
height: 100%;
}
.result {
position: absolute;
height: 320px;
width: 100%;
left: 0; top: 50%;
margin-top: -160px;
text-align: center;
padding: 10px;
display: none;
}
.result span {
display: inline-block;
font-size: 25px;
width: 150px;
background: #fff;
line-height: 30px;
color: #000;
margin: 5px;
border-radius: 10px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.8);
padding: 10px 0;
}
button, input, optgroup, select, textarea {
color: inherit;
font: inherit;
margin: 0;
border: none;
}
button {
overflow: visible;
}
button, select {
text-transform: none;
}
button, html input[type=button], input[type=reset], input[type=submit] {
-webkit-appearance: button;
cursor: pointer;
}
.pure-button {
display: inline-block;
zoom: 1;
line-height: normal;
white-space: nowrap;
vertical-align: middle;
text-align: center;
cursor: pointer;
-webkit-user-drag: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.pure-button {
font-family: inherit;
font-size: 100%;
padding: .5em 1em;
color: #444;
color: rgba(0,0,0,.8);
border: 0 rgba(0,0,0,0);
background-color: #E6E6E6;
text-decoration: none;
border-radius: 2px;
}
.pure-button:focus {
outline: 0
}
.pure-button-hover, .pure-button:hover, .pure-button:focus {
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000', endColorstr='#1a000000', GradientType=0);
background-image: -webkit-gradient(linear,0 0,0 100%,from(transparent),color-stop(40%,rgba(0,0,0,.05)),to(rgba(0,0,0,.1)));
background-image: -webkit-linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1));
background-image: -moz-linear-gradient(top,rgba(0,0,0,.05) 0,rgba(0,0,0,.1));
background-image: -o-linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1));
background-image: linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1));
}
.button-success, .button-error, .button-warning, .button-secondary {
color: white;
border-radius: 4px;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.button-success {
background: rgb(28, 184, 65);
}
.button-error {
background: rgb(202, 60, 60);
}
.button-warning {
background: rgb(223, 117, 20);
}
.button-secondary {
background: rgb(66, 184, 221);
}
.tools {
position: absolute;
bottom: 20px;
right: 20px;
text-align: center;
}
.tools .pure-button {
display: inline-block;
margin: 5px;
padding: 10px 0;
text-align: center;
width:50px;
}
.mask {
-webkit-filter:blur(5px);
}
#main {
-webkit-transition: all 1s;
transition: all 1s;
}
</style>
</head>
<body>
<div id="main" class="wall"></div>
<div id="result" class="result"></div>
<div id="tools" class="tools">
<button
v-on="click: onClick($value)"
class="pure-button"
v-class="button-error: selected == $value"
v-repeat="btns">{{$value}}</button>
<button
class="pure-button"
v-on="click: toggle"
v-class="
button-secondary: !running,
button-success: running
">{{running?'停!':'开始'}}</button>
<button class="pure-button button-warning" v-on="click: reset">重置</button>
</div>
<script type="text/javascript" src="js/zepto.js"></script>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript" src="js/tagcanvas.js"></script>
<script type="text/javascript" src="js/member.js"></script>
<script type="text/javascript">
(function(){
var choosed = JSON.parse(localStorage.getItem('choosed')) || {};
console.log(choosed);
var speed = function(){
return [0.1 * Math.random() + 0.01, -(0.1 * Math.random() + 0.01)];
};
var getKey = function(item){
return item.name + '-' + item.phone;
};
var createHTML = function(){
var html = [ '<ul>' ];
member.forEach(function(item, index){
item.index = index;
var key = getKey(item);
var color = choosed[key] ? 'yellow' : 'white';
html.push('<li><a href="#" style="color: ' + color + ';">' + item.name + '</a></li>');
});
html.push('</ul>');
return html.join('');
};
var lottery = function(count){
var total = member.length;
var ret = [];
var list = canvas.getElementsByTagName('a');
var color = '#' + ('00000' + Math.floor(Math.random() * 0xffffff)).slice(-6);
var color = 'yellow';
for(var i = 0; i < count; i++){
do {
var id = Math.ceil(Math.random() * total);
if(member[id]){
var key = getKey(member[id]);
}
} while(choosed[key]);
choosed[key] = 1;
ret.push(member[id].name + '<br/>' + member[id].phone);
list[id].style.color = color;
}
localStorage.setItem('choosed', JSON.stringify(choosed));
return ret;
};
var canvas = document.createElement('canvas');
canvas.id = 'myCanvas';
canvas.width = document.body.offsetWidth;
canvas.height = document.body.offsetHeight;
document.getElementById('main').appendChild(canvas);
new Vue({
el: '#tools',
data: {
selected: 30,
running: false,
btns: [
30, 10, 5, 2, 1
]
},
ready: function(){
canvas.innerHTML = createHTML();
TagCanvas.Start('myCanvas', '', {
textColour: null,
initial: speed(),
dragControl: 1,
textHeight: 14
});
},
methods: {
reset: function(){
if(confirm('确定要重置么?所有之前的抽奖历史将被清除!')){
localStorage.clear();
location.reload(true);
}
},
onClick: function(num){
$('#result').css('display', 'none');
$('#main').removeClass('mask');
this.selected = num;
},
toggle: function(){
if(this.running){
TagCanvas.SetSpeed('myCanvas', speed());
var ret = lottery(this.selected);
$('#result').css('display', 'block').html('<span>' + ret.join('</span><span>') + '</span>');
TagCanvas.Reload('myCanvas');
setTimeout(function(){
localStorage.setItem(new Date().toString(), JSON.stringify(ret));
$('#main').addClass('mask');
}, 300);
console.log(ret);
} else {
$('#result').css('display', 'none');
$('#main').removeClass('mask');
TagCanvas.SetSpeed('myCanvas', [5, 1]);
}
this.running = !this.running;
}
}
});
})();
</script>
</body>
</html>