<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Title> js lottery </title> <Style type = "text/css"> Td {width: 50px; height: 50px; border: 3px solid # ccc; text-align: center; vertical-align: middle} </Style> </Head> <Body> <Table id = "tb"> <Tr> <Td> 1 </td> <td> 2 </td> <td> 3 </td> <td> 4 </td> <td> 5 </td> </Tr> <Tr> <Td> 16 </td> <td> 6 </td> </Tr> <Tr> <Td> 15 </td> <td> 7 </td> </Tr> <Tr> <Td> 14 </td> <td> 8 </td> </Tr> <Tr> <Td> 13 </td> <td> 12 </td> <td> 11 </td> <td> 10 </td> <td> 9 </td> </Tr> </Table> <P> </p> Enter one of the integers from 1 to 16, <input id = "txtnum" value = "12" type = "text"/> <input type = "button" value = "start" onclick = "StartGame "() "/> <Script type = "text/javascript"> /* * Delete spaces between the left and right sides. */ Function Trim (str ){ Return str. replace (/(^ \ s *) | (\ s * $)/g ,""); } /* * Define an array */ Function GetSide (m, n ){ // Initialize the Array Var arr = []; For (var I = 0; I <m; I ++ ){ Arr. push ([]); For (var j = 0; j <n; j ++ ){ Arr [I] [j] = I * n + j; } } // Obtain the outermost circle of the array Var resultArr = []; Var tempX = 0, TempY = 0, Direction = "Along ", Count = 0; While (tempX> = 0 & tempX <n & tempY> = 0 & tempY <m & count <m * n) { Count ++; ResultArr. push ([tempY, tempX]); If (direction = "Along "){ If (tempX = N-1) TempY ++; Else TempX ++; If (tempX = n-1 & tempY = m-1) Direction = "Inverse" } Else { If (tempX = 0) TempY --; Else TempX --; If (tempX = 0 & tempY = 0) Break; } } Return resultArr; } Var index = 0, // the current position in the bright area PrevIndex = 0, // the previous position Speed = 300, // initial Speed Time, // define the object Arr = GetSide (5, 5), // initialize the Array EndIndex = 0, // determines where the speed slows down Tb = document. getElementById ("tb"), // get the tb object Cycle = 0, // Number of rotated circles EndCycle = 0, // calculate the number of circles Flag = false, // indicates the stop rotation. Quick = 0; // Acceleration Function StartGame (){ Cycle = 0; Flag = false; EndIndex = Math. floor (Math. random () * 16 ); // EndCycle = Math. floor (Math. random () * 4 ); EndCycle = 1; Time = setInterval (Star, Speed ); } Function Star (num ){ // Variable Speed If (flag = false ){ // Start acceleration in five cells If (quick = 5 ){ ClearInterval (Time ); Speed = 50; Time = setInterval (Star, Speed ); } // Run N laps to slow down If (cycle = EndCycle + 1 & index = EndIndex ){ ClearInterval (Time ); Speed = 300; Flag = true; // trigger end Time = setInterval (Star, Speed ); } } If (index> = arr. length ){ Index = 0; Cycle ++; } // Stop turning and select the number If (flag = true & index = parseInt (Trim (document. getElementById ("txtnum"). value)-1 ){ Quick = 0; ClearInterval (Time ); } Tb. rows [arr [index] [0]. cells [arr [index] [1]. style. border = "3px solid red "; If (index> 0) PrevIndex = index-1; Else { PrevIndex = arr. length-1; } Tb. rows [arr [prevIndex] [0]. cells [arr [prevIndex] [1]. style. border = "3px solid # ccc "; Index ++; Quick ++; } /* Window. onload = function (){ Time = setInterval (Star, Speed ); } */ </Script> </Body> </Html> |