SoFunction
Updated on 2025-03-02

How to implement JS digital lottery game

This article describes the implementation method of JS digital lottery game. Share it for your reference. The specific implementation method is as follows:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>New Year web lottery program</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" ? (id) : id;
 }, 
 $$: function (elem, oParent)
 {
  return (oParent || document).getElementsByTagName(elem);
 },
 addEvent: function (oElement, sEvent, fnHandler) 
 {
   ? (sEvent, fnHandler, false) : ("on" + sEvent, fnHandler) 
 },
 removeEvent: function (oElement, sEvent, fnHandler) 
 {
   ? (sEvent, fnHandler, false) : ("on" + sEvent, fnHandler)
 }, 
 getElementClient: function (){
  var arr = [];
  if ( &&  && ){
   ();
   ();
   return arr;
  }
 },
 getStyle: function (obj, attr)
 {
  return parseFloat( ? [attr] : getComputedStyle(obj, null)[attr])
 },
 startMove: function (obj, pos, onEnd)
 {
  clearInterval();
  var _this = this;
   = setInterval(function ()
  {
   _this.doMove(obj, pos, onEnd)
  }, 30) 
 },
 doMove: function (obj, pos, onEnd)
 {
  var iCurL = (obj, "left");
  var iCurT = (obj, "top");
  var iSpeedL = ( - iCurL) / 5;
  var iSpeedT = ( - iCurT) / 5;
  iSpeedL = iSpeedL > 0 ? (iSpeedL) : (iSpeedL);
  iSpeedT = iSpeedT > 0 ? (iSpeedT) : (iSpeedT);
  if ( == iCurL &&  == iCurT)
  {
   clearInterval();
   onEnd && onEnd()
  }
  else
  {
    = iCurL + iSpeedL + "px";
    = iCurT + iSpeedT + "px"; 
  }
 }
}
function Draw (obj, num)
{
  = obj;
  = num;
  = [];
  = [];
  = 0;
  = true;
  = true;
  = 0;
  = 0;
 ();  
}
 = {
 initialize: function ()
 {
   ();
   ();
   ();
   (); 
 },
 createElement: function ()
 {
  for(var j=0; j<; j++){ 
   var ul = ("ul");
   for(var i=0; i<10; i++){
    var li = ("li");
     = i;
    (li) 
   } 
   [j].appendChild(ul);
   [j].btn = true;
   AIR.$$("ul",[j])[0].innerHTML += AIR.$$("ul",[j])[0].innerHTML;  
  } 
  var UL = AIR.$$("ul",[0])[0];
   = (AIR.$$("li",UL)[0],"height");
   = AIR.$$("li",UL).length * 
 },
 randomSort: function (a, b) {
  return ()>.5 ? -1 : 1;
 },
 createArr: function ()
 {
  for(var i=0; i<+1; i++){
   (i);   
  } 
  (); 
 },
 closeEvent: function ()
 {
  ===function()
  {
   return false; 
  }  
 },
 startDraw: function ()
 {
  var _this = this;
   = function ( ev )
  {
   var ev = ev || ;
   if( == 13 ||  == 32){
    if(_this.btn && _this.timer){
     if(_this.obj[_this.-1].btn){
      _this.Play ();
      _this.btn = !_this.btn;
      _this.timer = !_this.timer; 
     }      
    }else{
     if(_this.obj[_this.-1].btn){
      _this.Stop ();
      _this.btn = !_this.btn;
      _this.timer = !_this.timer; 
     }
    }
    return false;
   }else{
    return false; 
   }
  }
 },
 Play: function ()
 {
  if( && ){
   var t = 0;
   for(var i=0; i<; i++){
    [i].btn = false;
     ([i],t); 
    t += 1500;
   }
  }else{
   return false; 
  }
 },
 playTimer: function (obj,t)
 {
  var _this = this;
  setTimeout(function(){
   _this.Move (obj);
  },t) 
 },
 Del: function (a)
 {
  for(var i=0; i<; i++){
   if(a == [i]){
    (i,1); 
   } 
  } 
 },
 Stop: function ()
 {
  if(! && !){
   var n =  + 1;
   var r = [(() * (0-n) + n)];
    = r;
    (r);
   r = ().split("");
   var c =  - ;
   if( < ){
    for(var i=0; i<c; i++){
     (0) 
    } 
   }
    = r; 
   // = r+" : "+; 
   var t = 0;
   for(var i=0; i<; i++){
    [i].btn = false;
    [i].index = i;
    [i].num = [[i].index];
     ([i],t); 
    t += 1500;
   }
  }
 },
 stopTimer: function (obj,t)
 {
  var _this = this;
  setTimeout(function(){
   _this.showResult (obj);
  },t)
 },
 showResult: function (obj)
 { 
  var _this = this;
   = true;
   = true;
   = false;
   = - * ;
   = setInterval(function(){
    -= 1;
   if( == 1){
    clearInterval(); 
    clearInterval();
     = setInterval(function(){
     if( >= ){
      clearInterval();
      (,{left:0,top:},function(){
        = true; 
       var set = true;
       for(var i=0; i<_this.; i++){
        if(!_this.obj[i].btn){
         set = false;  
        }
       }
       if(set){
        _this.Open(_this.show) 
       }
      });
     }
      =  +  +"px"; 
    },30);
   }
  },100);  
 },
 Open: function (num)
 {
   += " "+ num;
 },
 Move: function (obj)
 {
  var _this = this;
  var obj = obj;
   = false;
   = null;
   = 1;
   = AIR.$$("ul",obj)[0];
   =  +"px";
   = setInterval(function(){
   if( > 0){
     = -(_this.uh/2) +"px";
   }
    =  +  +"px"; 
  },30);
   = setInterval(function(){
    += 1;
   if( == 30){
    clearInterval();
     = true; 
   }
  },300) 
 }
}
var initialize = function ()
{
 new Draw ([AIR.$("box1"),AIR.$("box2"),AIR.$("box3")],100);
 reSize ();
}
var reSize = function ()
{
 var v = ();
 AIR.$$("img",AIR.$("back"))[0].width = v[0];
 AIR.$$("img",AIR.$("back"))[0].height = v[1]; 
}
(window,"load",initialize);
(window,"resize",reSize);
</script>
</head>
<body>
<div >
 <div ></div>
 <div ></div>
 <div ></div>
 <div style="clear:both"></div>
</div>
<div >
 <img src="images/" />
</div>
<div >100</div>
</body>
</html>

I hope this article will be helpful to everyone's JavaScript programming.