js realizes lottery function

  • 2021-09-24 21:19:37
  • OfStack

In this paper, we share the specific code of js to realize the lottery function for your reference. The specific contents are as follows

html section:


<div id="title" class="title"> Let's start the lottery </div>
 <div class="btns">
 <span id="play"> Begin </span>
 <span id="stop"> End </span>
</div>

css section:


 *{
 margin: 0;
 padding: 0;
 }
 .title{
 width: 400px;
 height:70px ;
 /* Horizontal center */
 margin: 0 auto;
 padding-top: 30px;
 text-align: center;
 font-size: 24px;
 color:#F00;
 }
 .btns{
 width: 190px;
 height: 30px;
 margin: 0 auto;
 }
 .btns span{
 display: block;
 float:left;
 width:80px;
 height:27px;
 line-height:27px;
 background:#036;
 border:1px solid #eee;
 border-radius:7px;
 margin-right:10px;
 color:#FFF;
 text-align:center;
 font-size:14px;
 font-family:" Microsoft Yahei ";
 cursor:pointer;
 }

Js section:


var data=['Phone5','Ipad',' Notebook ',' Camera ',' Printer ',' Thank you for your participation ','50 Yuan coupon '];
var timer=null;

 window.function(){
 var play=document.getElementById('play');
 var stop=document.getElementById('stop');
 play.playFun;
 stop.stopFun;
 }
 function playFun(){
 var play=document.getElementById('play');
 var title=document.getElementById('title');
 clearInterval(timer);

 timer=setInterval(function(){
 var random=Math.floor(Math.random()*data.length);
 title.innerHTML=data[random];
 },50)
 play.style.background='#eee';
 }
 function stopFun(){
 var play=document.getElementById('play');
 clearInterval(timer);
 play.style.background='#036';
 }

To learn more about the implementation of the lottery function, please refer to this topic: Lottery function


Related articles: