Home > Article > Backend Development > PHP+jQuery develops the function of simple card flop lottery (code example)
PHP jQuery develops a simple example of flip card lottery. The implementation process is as follows: 6 squares are placed on the page as prizes. When the lottery winner clicks on a certain square, the square flips to the back to display the winning information. This prize is random and not fixed.
Place 6 awards on the page:
<ul id="prize"> <li class="red" title="点击抽奖">1</li> <li class="green" title="点击抽奖">2</li> <li class="blue" title="点击抽奖">3</li> <li class="purple" title="点击抽奖">4</li> <li class="olive" title="点击抽奖">5</li> <li class="brown" title="点击抽奖">6</li> </ul>
Click each square, the event triggered:
$("#prize li").each(function() { var p = $(this); var c = $(this).attr('class'); p.css("background-color", c); p.click(function() { $("#prize li").unbind('click'); //连续翻动 $.getJSON("ajax.php", function(json) { var prize = json.yes; //抽中的奖项 p.flip({ direction: 'rl', //翻动的方向rl:right to left content: prize, //翻转后显示的内容即奖品 color: c, //背景色 onEnd: function() { //翻转结束 p.css({ "font-size": "22px", "line-height": "100px" }); p.attr("id", "r"); //标记中奖方块的id $("#viewother").show(); //显示查看其他按钮 $("#prize li").unbind('click').css("cursor", "default").removeAttr("title"); } }); $("#data").data("nolist", json.no); //保存未中奖信息 }); }); });
Turn over other squares :
$("#viewother").click(function() { var mydata = $("#data").data("nolist"); //获取数据 var mydata2 = eval(mydata); //通过eval()函数可以将JSON转换成数组 $("#prize li").not($('#r')[0]).each(function(index) { var pr = $(this); pr.flip({ direction: 'bt', color: 'lightgrey', content: mydata2[index], //奖品信息(未抽中) onEnd: function() { pr.css({ "font-size": "22px", "line-height": "100px", "color": "#333" }); $("#viewother").hide(); } }); }); $("#data").removeData("nolist"); });
For more related php knowledge, please visit php tutorial!
The above is the detailed content of PHP+jQuery develops the function of simple card flop lottery (code example). For more information, please follow other related articles on the PHP Chinese website!