php+lottery.js製做九宮格抽獎實例,本抽獎功能效果表現好,定製方便簡單,新手學習跟直接拿來用都很是不錯,兼容IE、火狐、谷歌等瀏覽器。javascript
引入抽獎插件lottery.jsphp
<script type="text/javascript" src="js/lottery.js"></script>
開始抽獎函數start_lottery()java
function start_lottery(){ if(flag){ //alert('正在抽獎,請等待抽獎結果!'); //return false; return void(0); } flag=true; index = 1; //當前選中對象的位置 fast = rand(3,6); //在哪一個位置開始加速 cycle = rand(3,5); //轉動多少圈 speed = 300; //開始時速度 $.ajax({ url: 'lottery.php', type: "post", data:null, dataType: "json", timeout: 20000, cache: false, beforeSend: function(){// 提交以前 }, error: function(){//出錯 flag=false; }, success: function(res){//成功 if(typeof(res.award_id)!='undefined'){ lucky = res.award_id; //中獎號碼 award = res.award_name; //獎品名稱 show_lottery(); }else{ flag=false; alert(res.err); } } }); }
PHP裏獎品配置ajax
//獎品配置 $award = array( // 獎品ID => array('獎品名稱',機率) 1 => array('悟空公仔',0.1), 2 => array('小乖虎公仔',0.1), 3 => array('神祕大禮包',0.1), 4 => array('智能遊戲手柄',0.1), 5 => array('小角鹿公仔',0.1), 6 => array('豆蛙抱枕',0.1), 7 => array('遊戲耳機',0.2), 8 => array('雷蛇鍵盤',0.2), ); $r =rand(1,100);