相思资源网 Design By www.200059.com
本文实例讲述了JS数字抽奖游戏实现方法。分享给大家供大家参考。具体实现方法如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新年网页抽奖程序</title>
<style type="text/css">
* {margin:0; padding:0;}
ul,li {list-style-type:none;}
body {overflow:hidden;}
#back {width:100%; height:100%;
background:#f5f5f5; position:absolute; z-index:1;
}
#box {width:360px; height:100px;
position:absolute; z-index:3; top:50%; left:50%;
margin-top:-50px; margin-left:-180px; text-align:center;
}
#box1,#box2,#box3 {width:100px; height:100px;
line-height:100px;
float:left; background:#321c24;
border:10px #321c24 solid;
border-radius:50%; position:relative; overflow:hidden;
}
#box1 ul,#box2 ul,#box3 ul {color:#fff; font-size:68px;
font-family:"Arial Black"; text-align:center;
width:100px; height:100px; line-height:100px;
position:absolute; top:0; left:0;
}
#box1 ul li,#box2 ul li,#box3 ul li {
width:100px; height:100px;
background:red; border-radius:50%;
}
</style>
<script type="text/javascript">
var AIR = {
$: function (id)
{
return typeof id === "string" "on" + sEvent, fnHandler)
},
removeEvent: function (oElement, sEvent, fnHandler)
{
oElement.removeEventListener "on" + sEvent, fnHandler)
},
getElementClient: function (){
var arr = [];
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth){
arr.push(document.documentElement.clientWidth);
arr.push(document.documentElement.clientHeight);
return arr;
}
},
getStyle: function (obj, attr)
{
return parseFloat(obj.currentStyle "left");
var iCurT = this.getStyle(obj, "top");
var iSpeedL = (pos.left - iCurL) / 5;
var iSpeedT = (pos.top - iCurT) / 5;
iSpeedL = iSpeedL > 0 "px";
obj.style.top = iCurT + iSpeedT + "px";
}
}
}
function Draw (obj, num)
{
this.obj = obj;
this.num = num;
this.data = [];
this.result = [];
this.show = 0;
this.btn = true;
this.timer = true;
this.h = 0;
this.uh = 0;
this.initialize();
}
Draw.prototype = {
initialize: function ()
{
this.createArr ();
this.createElement ();
this.closeEvent ();
this.startDraw ();
},
createElement: function ()
{
for(var j=0; j<this.obj.length; j++){
var ul = document.createElement("ul");
for(var i=0; i<10; i++){
var li = document.createElement("li");
li.innerHTML = i;
ul.appendChild(li)
}
this.obj[j].appendChild(ul);
this.obj[j].btn = true;
AIR.$$("ul",this.obj[j])[0].innerHTML += AIR.$$("ul",this.obj[j])[0].innerHTML;
}
var UL = AIR.$$("ul",this.obj[0])[0];
this.h = AIR.getStyle(AIR.$$("li",UL)[0],"height");
this.uh = AIR.$$("li",UL).length * this.h
},
randomSort: function (a, b) {
return Math.random()>.5 "");
var c = this.obj.length - r.length;
if(r.length < this.obj.length){
for(var i=0; i<c; i++){
r.unshift(0)
}
}
this.result = r;
//document.title = r+" : "+this.data;
var t = 0;
for(var i=0; i<this.obj.length; i++){
this.obj[i].btn = false;
this.obj[i].index = i;
this.obj[i].num = this.result[this.obj[i].index];
this.stopTimer (this.obj[i],t);
t += 1500;
}
}
},
stopTimer: function (obj,t)
{
var _this = this;
setTimeout(function(){
_this.showResult (obj);
},t)
},
showResult: function (obj)
{
var _this = this;
this.timer = true;
this.btn = true;
obj.btn = false;
obj.vh = -obj.num * this.h;
obj.timeOut = setInterval(function(){
obj.speed -= 1;
if(obj.speed == 1){
clearInterval(obj.timeOut);
clearInterval(obj.timer);
obj.timer = setInterval(function(){
if(obj.ul.offsetTop >= obj.vh){
clearInterval(obj.timer);
AIR.startMove(obj.ul,{left:0,top:obj.vh},function(){
obj.btn = true;
var set = true;
for(var i=0; i<_this.obj.length; i++){
if(!_this.obj[i].btn){
set = false;
}
}
if(set){
_this.Open(_this.show)
}
});
}
obj.ul.style.top = obj.ul.offsetTop + obj.speed +"px";
},30);
}
},100);
},
Open: function (num)
{
document.title += " "+ num;
},
Move: function (obj)
{
var _this = this;
var obj = obj;
obj.btn = false;
obj.timer = null;
obj.speed = 1;
obj.ul = AIR.$$("ul",obj)[0];
obj.ul.style.height = this.uh +"px";
obj.timer = setInterval(function(){
if(obj.ul.offsetTop > 0){
obj.ul.style.top = -(_this.uh/2) +"px";
}
obj.ul.style.top = obj.ul.offsetTop + obj.speed +"px";
},30);
obj.timeOut = setInterval(function(){
obj.speed += 1;
if(obj.speed == 30){
clearInterval(obj.timeOut);
obj.btn = true;
}
},300)
}
}
var initialize = function ()
{
new Draw ([AIR.$("box1"),AIR.$("box2"),AIR.$("box3")],100);
reSize ();
}
var reSize = function ()
{
var v = AIR.getElementClient();
AIR.$$("img",AIR.$("back"))[0].width = v[0];
AIR.$$("img",AIR.$("back"))[0].height = v[1];
}
AIR.addEvent(window,"load",initialize);
AIR.addEvent(window,"resize",reSize);
</script>
</head>
<body>
<div id="box">
<div id="box1"></div>
<div id="box2"></div>
<div id="box3"></div>
<div style="clear:both"></div>
</div>
<div id="back">
<img src="/UploadFiles/2021-04-02/20153291274950386.jpg">
希望本文所述对大家的javascript程序设计有所帮助。
标签:
JS,数字,抽奖游戏
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无JS数字抽奖游戏实现方法的评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。