Home>Article>Backend Development> PHP+jQuery develops the function of simple card flop lottery (code example)

PHP+jQuery develops the function of simple card flop lottery (code example)

藏色散人
藏色散人 forward
2020-01-27 16:09:54 2453browse

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.

PHP+jQuery develops the function of simple card flop lottery (code example)

Place 6 awards on the page:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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 visitphp 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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete