php+lottery.js制作九宫格抽奖实例

php+lottery.js制作九宫格抽奖实例,本抽奖功能效果表现好,定制方便简单,新手学习跟直接拿来用都非常不错,兼容IE、火狐、谷歌等浏览器。


引入抽奖插件lottery.js

<script type="text/javascript" src="js/lottery.js"></script>


开始抽奖函数start_lottery()

 1 function start_lottery(){ 
 2     if(flag){ 
 3         //alert('正在抽奖,请等待抽奖结果!'); 
 4         //return false; 
 5         return void(0); 
 6     } 
 7     flag=true; 
 8     index = 1;              //当前选中对象的位置 
 9     fast  = rand(3,6);      //在哪个位置开始加速 
10     cycle = rand(3,5);      //转动多少圈 
11     speed = 300;            //开始时速度 
12  
13     $.ajax({ 
14         url: 'lottery.php', 
15         type: "post", 
16         data:null, 
17         dataType: "json", 
18         timeout: 20000, 
19         cache: false, 
20         beforeSend: function(){// 提交之前 
21         }, 
22         error: function(){//出错 
23             flag=false; 
24         }, 
25         success: function(res){//成功 
26             if(typeof(res.award_id)!='undefined'){ 
27                 lucky = res.award_id;    //中奖号码 
28                 award = res.award_name;  //奖品名称 
29                 show_lottery(); 
30             }else{ 
31                 flag=false; 
32                 alert(res.err); 
33             } 
34         } 
35     }); 
36 }


PHP里奖品配置

 1 //奖品配置 
 2 $award = array( 
 3     // 奖品ID => array('奖品名称',概率) 
 4     1 => array('悟空公仔',0.1), 
 5     2 => array('小乖虎公仔',0.1), 
 6     3 => array('神秘大礼包',0.1), 
 7     4 => array('智能游戏手柄',0.1), 
 8     5 => array('小角鹿公仔',0.1), 
 9     6 => array('豆蛙抱枕',0.1), 
10     7 => array('游戏耳机',0.2), 
11     8 => array('雷蛇键盘',0.2), 
12 ); 
13  
14 $r =rand(1,100);


本文转自:https://www.sucaihuo.com/php/724.html 转载请注明出处!

猜你喜欢

转载自www.cnblogs.com/woleyia/p/11220723.html