js数字彩票游戏的实现方法
本文介绍了js数字彩票游戏的实现方法,供大家参考,具体的实现方法如下:新年网页抽奖计划
*边距:0;填充:0;}
UL,李{列表样式类型:无;}
主体{溢出:隐藏;}
#回来{宽度:100%;高度:100%;
背景:# f5f5f5;位置:绝对;Z指数:1;
}
#箱{宽度:360px;身高:100px;
位置:绝对;Z指数:3;最高:50%;左:50%;
边距:- 50px;margin-left: - 180px;文本对齐:中心;
}
# 1,#箱盒,# {宽度:100px;身高:100px;
行高:100px;
浮:左;背景:# 321c24;
边境:10px # 321c24固体;
边框半径:50%;位置:相对;溢出:隐藏;
}
# 1 UL,# Box2 UL,#盒UL {颜色:# FFF;字体大小:68px;
font-family:黑体;文本对齐:中心;
宽度:100px;身高:100px;线高度:100px;
位置:绝对值;顶部:0;左:0;
}
# 1 ul ul,#箱盒,# ul {
宽度:100px;身高:100px;
背景:红色;边框半径:50%;
}
var
$:函数(id)
{
返回类型ID =字符串document.getelementbyid ID(ID);
},
Suoyuan:功能(元素,oparent)
{
返回(oparent文件| |)。GetElementsByTagName(元);
},
AddEvent:功能(oelement,7,fnhandler)
{
OElement.addEventListener oElement.addEventListener(7,fnhandler,false):oelement.attachevent(+ 7,fnhandler)
},
removeevent:功能(oelement,7,fnhandler)
{
OElement.removeEventListener oElement.removeEventListener(7,fnhandler,false):oelement.detachevent(+ 7,fnhandler)
},
getelementclient:函数(){
var arr = { };
如果(document.documentelement document.documentelement.clientheight文档。文档元素}。clientwidth){
Arr.push(文档。文档元素}。clientwidth);
Arr.push(文档。文档元素}。自己);
报酬;
}
},
getstyle:功能(obj,ATTR)
{
返回parseFloat(obj.currentstyle OBJ。currentstyle {属性}:getcomputedstyle(obj,null){属性})
},
startmove:功能(obj,POS,竖着)
{
ClearInterval(obj。定时器);
无功_this =这;
obj.timer = setInterval(function())
{
_this.domove(obj,POS,竖着)
},30)
},
DoMove:功能(obj,POS,竖着)
{
无功icurl = this.getstyle(obj,左);
无功icurt = this.getstyle(obj,顶);
无功ispeedl =(pos.left - icurl) / 5;
无功ispeedt =(pos.top - icurt) / 5;
ispeedl = ispeedl > 0 math.ceil(ispeedl):Math.floor(ispeedl);
ispeedt = ispeedt > 0 math.ceil(ispeedt):Math.floor(ispeedt);
如果(pos.left = = icurl pos.top = = icurt)
{
ClearInterval(obj。定时器);
OnEnd onEnd()
}
其他的
{
obj.style.left = icurl + ispeedl +PX;
obj.style.top = icurt + ispeedt +PX;
}
}
}
函数绘制(obj,努姆)
{
this.obj = obj;
this.num =民;
this.data = { };
this.result = { };
这。= 0;
this.btn =真;
this.timer =真;
h=0;
this.uh = 0;
this.initialize();
}
draw.prototype = { {
初始化:函数()
{
This.createArr();
this.createelement();
This.closeEvent();
This.startDraw();
},
createElement():功能
{
对于(var j = 0;J < this.obj.length;j++){
VaR UL = document.createelement(UL);
对于(var i = 0;i < 10;i + +){
Var Li = document.createelement(礼);
li.innerhtml =我;
ul.appendchild(李)
}
This.obj{j}.appendChild (UL);
这个.obj { }按钮=真J;
空气。$(UL,这.obj {,}){ 0 } .innerHTML =空气。$(UL,这.obj {,}){ 0 }。innerHTML;
}
空= $()
这air.getstyle。H =(空气。$(李
this.uh =空气。$(李
},
RandomSort:功能(A,B){
返回Math.random()>。5 - 1:1;
},
CreateArr:()函数
{
对于(var i = 0;i < this 1 +;i + +){
This.data.push(我);
}
This.data.sort(这个。randomsort);
},
所以:()函数
{
文件。onmousedown =文件。移动鼠标=文件。OnContextMenu =功能()
{
返回false;
}
},
startdraw:功能()
{
无功_this =这;
document.onkeyup =功能(EV)
{
VaR EV = EV window.event | |;
如果(ev.keycode = = 13 | | { ev.keycode = = 32)
如果(_this.btn _this。定时器){
如果(_this .obj { _this .obj。length-1 }。BTN){
(_this。玩);
_this.btn =!_this.btn;
_this.timer =!_this.timer;
}
其他{ }
如果(_this .obj { _this .obj。length-1 }。BTN){
(_this。停止);
_this.btn =!_this.btn;
_this.timer =!_this.timer;
}
}
返回false;
其他{ }
返回false;
}
}
},
游戏:(功能)
{
如果(this.timer,BTN){
var = 0;
对于(var i = 0;i < this.obj.length;i++){
这个.obj {我}建立虚假;
This.playTimer(这个.obj {我},T);
T=1500;
}
其他{ }
返回false;
}
},
playtimer:功能(obj,T)
{
无功_this =这;
setTimeout(){()函数(
_this.move(obj);
},t)
},
函数(a)
{
对于(var i = 0;i < this.data.length;i++){
如果(a = =,此数据{ }){
this.data.splice(I,1);
}
}
},
停止:(功能)
{
如果(!this.timer!这个按钮){
var n = this.num + 1;
VAR r这个数据{ math.floor(Math.random()*(0-N)+ n)};
这。= R;
这个。德尔(R);
R = r.tostring()。分裂();
var c = this.obj.length - r.length;
If (r.length < this.obj.length) {
对于(var i = 0;i < C;i + +){
R.unshift(0)
}
}
this.result = R;
/ / document.title = R +:+ this.data;
var = 0;
对于(var i = 0;i < this.obj.length;i++){
这个.obj {我}建立虚假;
这个.obj {我}。指数=我;
这个.obj {我}。Num =这。结果{ .obj {我}。指数};
This.stopTimer(这个.obj {我},T);
T=1500;
}
}
},
stoptimer:功能(obj,T)
{
无功_this =这;
setTimeout(){()函数(
_this.showresult(obj);
},t)
},
显示诊断结果:功能(obj)
{
无功_this =这;
this.timer =真;
this.btn =真;
obj.btn = false;
obj.vh = -obj.num *本。H;
obj.timeout = setInterval(){()函数(
obj.speed = 1;
如果(obj.speed = = 1){
ClearInterval(obj。超时);
ClearInterval(obj。定时器);
obj.timer = setInterval(){()函数(
如果(obj.ul.offsettop = obj,VH){
ClearInterval(obj。定时器);
air.startmove(obj.ul,{左:0,上:obj。VH },函数()){
obj.btn =真;
变量集=真值;
对于(var i = 0;i < _this.obj.length;i++){
如果(!_this .obj {我} { BTN)。
设置= false;
}
}
如果(设置){
_this.open(_this。节目)
}
});
}
obj.ul.style.top = obj.ul.offsettop + obj.speed +PX;
},30);
}
},100);
},
开放:功能(努姆)
{
document.title =+数字;
},
移动:功能(obj)
{
无功_this =这;
var obj = obj;
obj.btn = false;
obj.timer = null;
obj.speed = 1;
obj.ul =空气。$(UL
obj.ul.style.height = this.uh +PX;
obj.timer = setInterval(){()函数(
如果(obj.ul.offsettop > 0){
obj.ul.style.top = -(_this。嗯 / 2)+PX;
}
obj.ul.style.top = obj.ul.offsettop + obj.speed +PX;
},30);
obj.timeout = setInterval(){()函数(
obj.speed = 1;
如果(obj.speed = = 30){
ClearInterval(obj。超时);
obj.btn =真;
}
},300)
}
}
函数()
{
新画({空气。$(1)、空气。$(箱)、空气。$(盒)},100);
调整大小();
}
var大小=函数()
{
var v = air.getelementclient();
空气。$(img
空气。$(img
}
air.addevent(窗口,负荷
air.addevent(窗口,调整
一百
希望本文能对大家的javascript程序设计有所帮助。