This article mainly introduces examples of how js achieves the lottery effect. It has good reference value. Next let's take a look at the small Editor. This article mainly introduces examples of how js achieves the lottery effect. It has good reference value. Let's take a look at it with the small Editor.
:
The Code is as follows:
Random lottery Lucky DrawStart drawing
Stop lottery drawing
Congratulations! You have obtained:
Script var arr = ["Samsung", "apple", "Huawei honor", "Xiaomi", "meizu", "ZTE Nubian", "kupi ", "vivo (blue factory)", "oppo (Green factory)"]; // array added cyclically var lieshu = 3; // Number of columns console. log (arr. length); console. log ("can be divided into:" + arr. length/lieshu + "row"); for (var I = 0; I "+ arr [I * lieshu + j] +"");/* Document. write File In the webpage I * lieshu + j is the number * (j * 110 + 500) 110 is the column margin 500 for the entire table; column offset * (I * 40 + 300) 40 rows with a spacing of 300 are the entire table; column offset ***/} var bs =-1; // used to change the color after loop var t; function ks () {/* method for starting color change */if (bs! =-1) {document. getElementById ("jiang" + bs ). style. background = "# ff3030";} var shuijisu = Math. floor (Math. random () * arr. length); // generate arr. length: random number. getElementById ("jiang" + shuijisu ). style. background = "# 3500cc"; bs = shuijisu; // The following table t = setTimeout ("ks ()", 100) for adding elements;} function gb () {clearTimeout (t); document. getElementById ("tx "). innerHTML = document. getElementById ("jiang" + bs ). innerHTML; // modify the id = "tx" class value} script
The above is the details of the graphic code sharing that js achieves the lottery effect. For more information, see other related articles in the first PHP community!