1 Star 1 Fork 0

识君/webLottery

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.html 24.21 KB
一键复制 编辑 原始数据 按行查看 历史
识君 提交于 2023-01-06 16:09 . first commit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
<!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(&quot;images/2.jpg&quot;) 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 &nbsp;<br>
<h2>二等奖</h2>员工M &nbsp;员工H &nbsp;<br>
<h2>三等奖</h2>员工E &nbsp;员工A &nbsp;员工I &nbsp;员工B &nbsp;<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>&nbsp;* 中奖名单 *&nbsp;';
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 += '&nbsp;|&nbsp;' + 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] + ' &nbsp;';
}
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] + ' &nbsp;';
}
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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/ssy_kr/web-lottery.git
git@gitee.com:ssy_kr/web-lottery.git
ssy_kr
web-lottery
webLottery
master

搜索帮助