Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Nine Miyagi Lottery by jquery

Shulou Source: shulou.com Published: 2022-06-02 09:07:31 10月01日 Update

This article mainly introduces how to realize the lucky draw of Nine Palace Lattice by jquery. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

The method to realize the lucky draw by jquery is as follows: 1, create the code displayed at the front end; 2, realize the lucky draw by jquery code "$(" # lottery a ") .click (function () {...}").

This article operating environment: windows7 system, jquery3.2.1 version, DELL G3 computer

An example of lottery draw for jquery-- Nine Palace turntable

First, the pictures used

Second, the code is as follows, focusing on the js part

JQuery # lottery {width:570px;height:510px;margin:0px auto;border:4px solid # ba1809;} # lottery table {background-color:yellow;} # lottery table td {position:relative;width:190px;height:170px;text-align:center;color:#333;font-index:-999} # lottery table td img {display:block;width:190px;height:170px;} # lottery table td a {width:190px;height:170px;display:block;text-decoration:none Background:url (images/lottery1.jpg) no-repeat top center;} # lottery table td a:hover {background-image:url (images/lottery2.jpg);} # lottery table td.active .mask {display:block;} .mask {width:100%; height:100%; position:absolute; left:0; top:0; background:url (images/mask.png) no-repeat; display:none;}

Var lottery= {index:-1, / / which position is currently rotated to, the starting position count:0, / / how many positions are there in total timer:0, / / ID of setTimeout Use clearTimeout to clear speed:20, / / initial rotation speed times:0, / / rotation times cycle:50, / / basic rotation times: that is, at least how many times do you need to rotate before entering the lottery prize:-1, / / the winning position init:function (id) {if ($("#" + id). Find (".lottery-unit") .length > 0) {$lottery = $("#" + id) $units = $lottery.find (".lottery-unit"); this.obj = $lottery; this.count = $units.length; $lottery.find (".lottery-unit-" + this.index) .addClass ("active");}, roll:function () {var index = this.index; var count = this.count; var lottery = this.obj; $(lottery) .find (".lottery-unit-" + index) .removeClass ("active") Index + = 1; if (index > count-1) {index= 0;}; $(lottery). Find (".lottery-unit-" + index) .addClass ("active"); this.index=index; return false;}, stop:function (index) {this.prize=index; return false;}}; function roll () {lottery.times + = 1; lottery.roll () / / the rotation process calls the roll method of lottery. Here is the first call to initialize if (lottery.times > lottery.cycle+10 & & lottery.prize==lottery.index) {clearTimeout (lottery.timer); lottery.prize=-1; lottery.times=0; click=false;} else {if (lottery.times lottery.cycle+10 & & ((lottery.prize==0 & & lottery.index==7) | | lottery.prize==lottery.index+1)) {lottery.speed + = 110 } else {lottery.speed + = 20;}} if (lottery.speed

Tags: Ninth house process code location content front end picture mobile phone effect method frequency item article turntable location event event value interest compatibility Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker Linux Redmi NVidia