本文實例講述了jQuery移動端跑馬燈抽獎特效升級版(抽獎概率固定)實現方法。分享給大家供大家參考,具體如下:
項目描述:九宮格的跑馬燈抽獎特效,抽中獎品1-9的概率分別是2%,2%,4%,1%,12%,1%,8%,70%,概率總計100%,并且每天抽獎次數最多為3次。
html部分的代碼和css部分的代碼和上一節《jQuery移動端跑馬燈抽獎特效》一樣,沒有修改,js部分有修改,增加了概率。
原理很簡單,同樣是取隨機數,判斷這個隨機數的大小在100的0-2,2-4,4-8,8-9,9-21,21-22,22-30,30-100之間的哪一個數組內,隨機就可判斷中哪個獎項。
代碼在前面一篇《jQuery移動端跑馬燈抽獎特效》js的代碼上面增加了一個maths_f()函數,如下:
function maths_f(maths){ if(maths>0&&maths<2){ console.log('恭喜獲得獎品1') twice=1; }else if(maths>=2&&maths<=4){ console.log('恭喜獲得獎品2') twice=2; }else if(maths>=4&&maths<8){ console.log('恭喜獲得獎品3') twice=3; }else if(maths>=8&&maths<9){ console.log('恭喜獲得獎品4') twice=4; }else if(maths>=9&&maths<21){ console.log('恭喜獲得獎品5') twice=5; }else if(maths>=21&&maths<22){ console.log('恭喜獲得獎品6') twice=6; }else if(maths>=22&&maths<30){ console.log('恭喜獲得獎品7') twice=7; }else if(maths>=30&&maths<100){ console.log('恭喜獲得獎品8') twice=8; } light();}
start()
函數也有修改,修改為:
$('.start').click(function() { if(click&&num>0) { click = false; maths = (Math.random() * 100); console.log(maths) maths_f(maths); } else { return false; }});
其他的自己看著改吧。
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery操作DOM節點方法總結》、《jQuery擴展技巧總結》、《jQuery常用插件及用法總結》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答