-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathindex.html
649 lines (546 loc) · 24.2 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>网页抽奖小工具</title>
<meta name="description" content="一个简单的在线抽奖系统, 可用于公司年会抽奖, 电视台抽奖等,可以自己设定抽奖名单、抽奖人数、每次出奖人数,有防止重复得奖的功能。">
<meta name="keywords" content="">
<meta name="baidu-tc-verification" content="3e8294dabe46e8def7d4b790be59d4cc">
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.7.2.custom.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<style type="text/css">
table {
margin: 12px auto;
border-collapse: collapse;
width: 95%;
background: #fff;
}
th,
td {
border: 2px solid #333;
}
label {
margin: 6px 0;
font-size: 14px;
font-weight: bold;
display: block;
}
input[type=text] {
width: 600px;
}
input {
width: expression(this.type=="text"?"600px":"auto");
}
textarea {
width: 600px;
}
#main {
color: #000;
margin: 0 auto;
padding-top: 40px;
;
width: 980px;
}
#event_title {
color: #ff0;
margin: 26px;
padding: 0;
font-size: 56px;
text-align: center;
}
#event_title span {
padding: 0 32px;
background: #f00;
}
#rolling_board {
color: #000;
line-height: 40px;
font-size: 40px;
font-weight: bold;
margin: 34px auto;
padding: 8px;
width: 640px;
text-align: center;
background: #ff3;
border: 6px solid #03f;
}
#current_step {
line-height: 42px;
font-size: 42px;
font-weight: bold;
}
#tabs {
padding: 0;
}
#tabs-1 {
padding: 4px;
font-size: 14px;
text-align: center;
border: 3px solid #33f;
height: 580px;
}
#tabs-2,
#tabs-3,
#tabs-4 {
padding: 4px;
border: 1px solid #ccc;
}
#tabs-3 h3,
#tabs-4 h3 {
padding-left: 6px;
border-left: 6px solid #c00;
}
#tabs-4 h2 {
text-align: center;
}
#rotate_div {
padding-top: 60px;
height: 400px;
}
#print_box {
margin-top: 30px;
font-weight: bold;
font-size: 28px;
width: 70%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
#print_box span {
margin: 4px;
color: #fff;
}
</style>
</head>
<body class="bg index">
<div id="container">
<div id="wrapper" class="mh">
<h2 style="text-align: center">在线抽奖</h2>
<div class="h20"></div>
<div class="content" style="text-align: center;">一个简单的在线抽奖系统, 可用于公司年会抽奖, 电视台抽奖等,可以自己设定抽奖名单、抽奖人数、每次出奖人数,有防止重复得奖的功能。</div>
<script type="text/javascript">
var game;
$(function() {
$('#loading').hide();
$('#tabs').slideDown('fast');
$('#tabs').tabs();
game = new Game();
save_setting();
});
// 绑定回车键盘操作
$(document).keypress(function(e) {
switch (e.which) {
case 13:
game.process();
break;
}
});
</script>
<div id="main">
<div id="loading" style="text-align: center; display: none;">
<h2>Loading...</h2>
</div>
<div id="tabs" style="display: block;" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<li class="ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">抽奖</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-2">设置</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-3">结果</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tabs-4">帮助</a></li>
</ul>
<div id="tabs-1" style="background: url("images/2.jpg") center center no-repeat;" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
<h1 id="event_title"><span>抽奖活动</span></h1>
<div id="rotate_div" style="display: block;">
<div><span id="current_step" style="display: none;">一等奖(1个)</span></div>
<div id="rolling_board" style="display: none;"><span style="color: #f33">员工L</span></div>
<div id="print_box" style="display: block;">请按回车开始</div>
</div>
</div>
<!-- /#tabs-1 -->
<div id="tabs-2" style="background: #fff;" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
<label>活动标题</label>
<div><input type="text" name="title" value="抽奖活动"></div>
<label>奖项设置</label>
<div>每行一个奖项, 格式为竖线分隔的: 奖项名|数量|每次抽几个|奖品</div>
<textarea name="prizes" rows="6" cols="84">
三等奖|4|2|美女1名/每人
二等奖|2|2|100万美金/每人
一等奖|1|1|10本世界名著/每人
</textarea>
<label>候选人列表</label>
<div>每行一人, 或半角逗号分隔</div>
<textarea name="candidates" rows="6" cols="84">
员工A
员工B
员工C
员工D
员工E
员工F
员工G
员工H
员工I
员工J
员工K
员工L
员工M
员工N
员工O
员工P
员工Q
员工R
员工S
员工T
员工U
员工V
员工W
员工X
员工Y
员工Z
</textarea>
<label>跳动时间间隔</label>
<div><input type="text" name="interval" value="50" style="width: 50px;"> ms</div>
<label>背景图片</label>
<div>可以输入图片链接使用网络上的图片, 也可以把图片拷贝到当前目录, 把图片文件名填入即可.</div>
<div><input name="background_image" type="text" value="images/2.jpg"></div>
<p><input type="button" value="保存" onclick="save_setting()"></p>
</div>
<!-- /#tabs-2 -->
<div id="tabs-3" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
<h2>一等奖</h2>员工L <br>
<h2>二等奖</h2>员工M 员工H <br>
<h2>三等奖</h2>员工E 员工A 员工I 员工B <br></div>
<!-- /#tabs-3 -->
<div id="tabs-4" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
<h2>抽奖软件</h2>
<p>在浏览器上运行的抽奖程序</p>
<h3>操作方便</h3>
<p>抽奖过程全键盘操作, 只需要按回车(Enter)键即可, 类似播放PPT幻灯片, 非常简单.</p>
<h3>配置灵活</h3>
<p>可配置的选项有: 活动标题, 奖项, 候选人, 摇奖时的跳转速度, 背景图片. 其中, 每一个奖项, 可以一次开完, 也可以一次只开一部分. 例如, 三等奖一共6个, 每次只开2个, 需要开3次才能开完三等奖, 增加娱乐性. 图片可以更换为带自己公司Logo的图片, 以便适应当前节日, 所以, 本抽奖程序任何节日的任何类似的抽奖节目都可使用.</p>
<h3>抽奖流程</h3>
<pre>
等待开始
开场(open): 奖项介绍
奖项循环: 如果多于一个奖项, 则循环
奖项开场(step_open)
摇奖循环: 如果不是一次开完一个奖项, 则循环
摇奖开始(rotate_start)
摇奖结束(rotate_stop)
奖项结束(step_close): 单项中奖名单
闭场(close)
</pre>
</div>
<!-- /#tabs-4 -->
</div>
<script type="text/javascript">
function in_array(item, list) {
for (var i = 0; i < list.length; i++) {
if (item == list[i]) {
return true;
}
}
return false;
}
/**
* 返回指定元素在数组中的索引, 如果没找到, 返回-1;
*/
function array_find(list, item) {
for (var i = 0; i < list.length; i++) {
if (item == list[i]) {
return i;
}
}
return -1;
}
// 从数组中删除元素. 返回新数组.
function array_del(list, item) {
var arr = [];
for (var i = 0; i < list.length; i++) {
if (item != list[i]) {
arr.push(list[i]);
}
}
return arr;
}
// 从数组中删除元素. 返回新数组.
function array_del_all(list, items) {
var arr = [];
for (var i = 0; i < list.length; i++) {
if (array_find(items, list[i]) == -1) {
arr.push(list[i]);
}
}
return arr;
}
/**
* 把数组当作环形的, 返回从start开始, 一共count个元素.
* 如果count大于数组长度, 返回整个数组.
*/
function array_slice(list, start, count) {
var ret;
ret = list.slice(start, start + count);
if (ret.length < count) {
ret = ret.concat(list.slice(0, count - ret.length));
}
return ret;
}
// 扰乱数组元素的顺序.
function array_shuffle(list) {
var len = list.length;
for (var i = 0; i < len * 5; i++) {
var p1 = parseInt(len * Math.random());
var p2 = parseInt(len * Math.random());
var tmp = list[p1];
list[p1] = list[p2];
list[p2] = tmp;
}
}
/*
状态/动作
开场(open)
循环{
奖项开场(step_open)
奖项抽奖(rotate_start)
奖项抽奖(rotate_stop)
奖项闭场(step_close)
}
闭场(close)
*/
var Game = function() {
var self = this;
this.step = -1;
this.interval = 100;
this.rotate_index = 0;
self.action = 'open';
this.prizes = [];
this.candidates = [];
this.results = [];
this.init = function() {
this.step = 0;
this.stop = false;
this.rotate_index = 0;
self.action = 'open';
this.results = [];
for (var i = 0; i < self.prizes.length; i++) {
var p = self.prizes[i];
self.results[i] = [];
}
show_current_step('');
var str = '请按回车开始';
str += '<br/><br/>';
print_box('请按回车开始');
$('#rolling_board').hide();
$('#rotate_div').css('background', '');
}
this.reset = function() {
this.prizes = [];
this.candidates = [];
this.results = [];
}
this.process = function() {
show_results();
// 先更新状态再执行函数
switch (self.action) {
case 'open':
self.action = 'step_open';
$('#rotate_div').hide();
on_open();
$('#rotate_div').fadeIn('slow');
break;
case 'close':
self.action = '';
on_close();
break;
case 'step_open':
self.action = 'rotate_start';
$('#rotate_div').hide();
on_step_open();
$('#rotate_div').fadeIn('fast');
break;
case 'step_close':
if (self.step == self.prizes.length) {
self.action = 'close';
} else {
self.action = 'step_open';
}
on_step_close();
break;
case 'rotate_start':
self.action = 'rotate_stop';
on_rotate_start();
break;
case 'rotate_stop':
on_rotate_stop();
break;
default:
save_setting();
break;
}
};
}
function on_open() {
show_current_step('活动说明');
var str = '<table align="center">';
str += '<tr><th>奖项</th><th>数量</th><th>奖品</th></tr>\n';
for (var i = game.prizes.length - 1; i >= 0; i--) {
var p = game.prizes[i];
str += '<tr><td>' + p.name + '</td><td>' + p.num + '</td><td>' + p.award + '</td></tr>\n';
}
str += '</table>';
print_box(str);
}
function on_close() {
show_current_step('');
$('#print_box').hide();
var str = '';
str += '<span><b style="font-size: 62px;">抽奖结束</b><span><br/>';
print_box(str);
$('#print_box').fadeIn('slow');
}
function on_step_open() {
show_current_step();
print_box('按回车开始');
$('#rolling_board').html('...');
}
function on_step_close() {
var str = '';
str += '<span> * 中奖名单 * ';
var r = game.results[game.step - 1];
for (var n = 0; n < r.length; n++) {
if(n % 2 == 0){
str += '<br/>' + r[n];
}else{
str += ' | ' + r[n];
}
}
str += '</span>';
print_box(str);
$('#rolling_board').slideUp('normal');
}
function on_rotate_start() {
$('#rolling_board').slideDown('normal');
game.interval = parseInt($('input[name=interval]').val());
game.stop = false;
game.rotate_index = 0;
// 打乱顺序
array_shuffle(game.candidates);
rotate_run();
show_current_step();
print_box('按回车停止');
}
function on_rotate_stop() {
// 等一段随机时间再停止.
game.interval += parseInt(0.9 * game.interval);
setTimeout('game.stop=true', 230 + parseInt(230 * Math.random()));
//game.stop = true;
}
function rotate_run() {
var num_a = game.prizes[game.step].num_a_time;
var size = game.prizes[game.step].num - game.results[game.step].length;
if (size > num_a) {
size = num_a;
}
var arr = array_slice(game.candidates, game.rotate_index, size);
$('#rolling_board').html(arr.join(' '));
game.rotate_index += num_a;
if (game.rotate_index >= game.candidates.length) {
game.rotate_index -= game.candidates.length;
}
if (game.stop) {
game.action = 'rotate_start';
game.results[game.step] = game.results[game.step].concat(arr);
game.candidates = array_del_all(game.candidates, arr);
show_results();
print_box('按回车继续');
if (game.results[game.step].length == game.prizes[game.step].num) {
game.step++;
game.action = 'step_close';
}
var h = '<span style="color: #f33">' + $('#rolling_board').html() + '</span>';
$('#rolling_board').html(h)
} else {
setTimeout('rotate_run()', game.interval);
}
}
function show_current_step(str) {
if (str == undefined) {
var found = game.results[game.step].length;
var all = game.prizes[game.step].num;
var num_a = game.prizes[game.step].num_a_time;
var b = (num_a + found) > all ? all : (num_a + found);
var str = game.prizes[game.step].name + '(' + game.prizes[game.step].num + '个';
if (num_a != all) {
str += ', ' + (found + 1) + '-' + b;
}
str += ')';
}
if (str == '') {
$('#current_step').hide('fast');
} else {
$('#current_step').html(str);
$('#current_step').show();
}
}
function print_box(str) {
if (str == undefined) {
var str = '<span>';
var r = game.results[game.step];
for (var n = 0; n < r.length; n++) {
str += r[n] + ' ';
}
str += '</span>';
}
if (str == '') {
$('#print_box').hide('fast');
} else {
$('#print_box').html(str);
$('#print_box').show();
}
}
function show_results() {
var str = '';
for (var i = game.results.length - 1; i >= 0; i--) {
str += '<h2>' + game.prizes[i].name + '</h2>';
var r = game.results[i];
for (var n = 0; n < r.length; n++) {
str += r[n] + ' ';
}
str += '<br/>';
}
$('#tabs-3').html(str);
}
function save_setting() {
game.reset();
var ps = $.trim($('textarea[name=prizes]').val()).split('\n');
for (var i = 0; i < ps.length; i++) {
var p = $.trim(ps[i]);
if (p.length == 0) {
continue;
}
var ex = p.split('|');
var prize = {
name: $.trim(ex[0]),
num: parseInt($.trim(ex[1])),
num_a_time: parseInt($.trim(ex[2])),
award: $.trim(ex[3])
};
game.prizes.push(prize);
}
var ps = $.trim($('textarea[name=candidates]').val()).replace(/,/g, '\n').split('\n');
for (var i = 0; i < ps.length; i++) {
var p = $.trim(ps[i]);
if (p.length == 0) {
continue;
}
game.candidates.push(p);
}
$('#event_title span').html($('input[name=title]').val());
$('#tabs-1').css('background', 'url(' + $('input[name=background_image]').val() + ') center center no-repeat');
game.init();
}
</script>
</div>
</div>
</div>
</body>
</html>