以下是 jQuery清爽的点名抽奖游戏代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>jQuery清爽的点名抽奖游戏代码</title>
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
#box{width:300px;height:100px;position:absolute;left:500px;top:200px;background:#5BD6F9;font-size:50px;text-align:center;line-height:100px;color:#FFFFFF;border-radius:10px;}
#jiang{width:300px;height:50px;background:red;position:absolute;left:500px;top:320px;border-radius:10px;text-align:center;line-height:50px;color:#FFFFFF;font-size:20px;}
#ji{width:300px;height:50px;background:pink;position:absolute;left:500px;top:400px;border-radius:10px;text-align:center;line-height:50px;color:#FFFFFF;font-size:20px;}
</style>
</head>
<body>
<button id="start">开始</button>
<button id="stop">停止</button>
<div id = "box">26班点名册</div>
<div id="jiang"></div>
<div id="ji"></div>
<script type="text/javascript">
//设置显示的所有抽奖名字
list = ['小名','小白','小黑','小红','小绿','小青','小猪',];
//最终抽奖结果会从下面的这个数组里选出
lis = ['小念','小狗狗'];
$('#start').click(function(){
$('#jiang').html('等待抽奖中');
immer = setInterval(function(){
num = Math.floor(Math.random() * list.length);
$('#box').html(list[num]);
},30)
});
$('#stop').click(function(){
clearInterval(immer);
num1 = Math.floor(Math.random() * lis.length);
$('#box').html(lis[num1]);
//设置抽奖结果
li = ['跳芭蕾舞','跳脱衣舞','一等奖','跳钢管舞'];
(function(){
se = setInterval(function(){
nu = Math.floor(Math.random() * li.length);
$('#jiang').html(li[nu]);
},30);
})();
});
</script>
<script type="text/javascript">
setInterval(function(){
var time = new Date();
var y = time.getFullYear();
// 月份取值 0-11
var m = time.getMonth() + 1;
var d = time.getDate();
var h = time.getHours();
var i = time.getMinutes();
var s = time.getSeconds();
$('#ji').html(y + '/' + m + '/' + d + ' ' + h + ':' + i + ':' + s);
if(s > 0){
clearInterval(se);
}
},1000);
</script>
</body>
</html>