jquery實現(xiàn)轉(zhuǎn)盤抽獎功能
實現(xiàn)這個其實蠻簡單的,轉(zhuǎn)動的效果用的jqueryRotate插件,所以只要判斷每個獎薦對應(yīng)的角度,然后設(shè)置指針的轉(zhuǎn)動角度就可以了。比如關(guān)鍵的是jqueryRotate這個插件的用法。
jqueryRotate的資料:
支持Internet Explorer 6.0+ 、Firefox 2.0 、Safari 3 、Opera 9 、Google Chrome,高級瀏覽器下使用Transform,低版本ie使用VML實現(xiàn)
google code地址:http://code.google.com/p/jqueryrotate/
調(diào)用和方法:
$(el).rotate({ angle:0, //起始角度 animateTo:180, //結(jié)束的角度 duration:500, //轉(zhuǎn)動時間 callback:function(){}, //回調(diào)函數(shù) easing: $.easing.easeInOutExpo //定義運動的效果,需要引用jquery.easing.min.js的文件 }) $(el).rotate(45); //直接這樣子調(diào)用的話就是變換角度 $(el).getRotateAngle(); //返回對象當(dāng)前的角度 $(el).stopRotare(); //停止旋轉(zhuǎn)動畫
另外可以更方便的通過調(diào)用$(el).rotateRight()和$(el).rotateLeft()來分別向右旋轉(zhuǎn)90度和向左旋轉(zhuǎn)90度。
很簡單吧,各種example可以看這里:http://code.google.com/p/jqueryrotate/wiki/Examples
下面是用jqueryRotate實現(xiàn)的抽獎轉(zhuǎn)盤頁面:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>轉(zhuǎn)盤</title> <style> *{padding:0;margin:0} body{ text-align:center } .ly-plate{ position:relative; width:509px; height:509px; margin: 50px auto; } .rotate-bg{ width:509px; height:509px; background:url(ly-plate.png); position:absolute; top:0; left:0 } .ly-plate div.lottery-star{ width:214px; height:214px; position:absolute; top:150px; left:147px; /*text-indent:-999em; overflow:hidden; background:url(rotate-static.png); -webkit-transform:rotate(0deg);*/ outline:none } .ly-plate div.lottery-star #lotteryBtn{ cursor: pointer; position: absolute; top:0; left:0; *left:-107px } </style> </head> <body> <div class="ly-plate"> <div class="rotate-bg"></div> <div class="lottery-star"><img src="rotate-static.png" id="lotteryBtn"></div> </div> </body> <script src="jquery-1.7.2.min.js"></script> <script src="jQueryRotate.2.2.js"></script> <script> $(function(){ var timeOut = function(){ //超時函數(shù) $("#lotteryBtn").rotate({ angle:0, duration: 10000, animateTo: 2160, //這里是設(shè)置請求超時后返回的角度,所以應(yīng)該還是回到最原始的位置,2160是因為我要讓它轉(zhuǎn)6圈,就是360*6得來的 callback:function(){ alert('網(wǎng)絡(luò)超時') } }); }; var rotateFunc = function(awards,angle,text){ //awards:獎項,angle:獎項對應(yīng)的角度,text:提示文字 $('#lotteryBtn').stopRotate(); $("#lotteryBtn").rotate({ angle:0, duration: 5000, animateTo: angle+1440, //angle是圖片上各獎項對應(yīng)的角度,1440是我要讓指針旋轉(zhuǎn)4圈。所以最后的結(jié)束的角度就是這樣子^^ callback:function(){ alert(text) } }); }; $("#lotteryBtn").rotate({ bind: { click: function(){ var time = [0,1]; time = time[Math.floor(Math.random()*time.length)]; if(time==0){ timeOut(); //網(wǎng)絡(luò)超時 } if(time==1){ var data = [1,2,3,0]; //返回的數(shù)組 data = data[Math.floor(Math.random()*data.length)]; if(data==1){ rotateFunc(1,157,'恭喜您抽中的一等獎') } if(data==2){ rotateFunc(2,247,'恭喜您抽中的二等獎') } if(data==3){ rotateFunc(3,22,'恭喜您抽中的三等獎') } if(data==0){ var angle = [67,112,202,292,337]; angle = angle[Math.floor(Math.random()*angle.length)] rotateFunc(0,angle,'很遺憾,這次您未抽中獎') } } } } }); }) </script> </html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
- jquery.rotate.js實現(xiàn)可選抽獎次數(shù)和中獎內(nèi)容的轉(zhuǎn)盤抽獎代碼
- jquery 年會抽獎程序
- jQuery實現(xiàn)轉(zhuǎn)動隨機(jī)數(shù)抽獎效果的方法
- jquery 抽獎小程序?qū)崿F(xiàn)代碼
- jquery實現(xiàn)九宮格大轉(zhuǎn)盤抽獎
- jQuery實現(xiàn)類似老虎機(jī)滾動抽獎效果
- jquery輸入數(shù)字隨機(jī)抽獎特效的簡單實現(xiàn)代碼
- jquery——九宮格大轉(zhuǎn)盤抽獎實例
- jQuery+PHP實現(xiàn)的擲色子抽獎游戲?qū)嵗?/a>
- jQuery實現(xiàn)移動端扭蛋機(jī)抽獎
相關(guān)文章
jQuery插件之Tocify動態(tài)節(jié)點目錄菜單生成器附源碼下載
Tocify是一個能夠動態(tài)生成文章節(jié)點目錄的jQuery插件,通過本文給大家分享jQuery插件之Tocify動態(tài)節(jié)點目錄菜單生成器,對tocify菜單生成器相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2016-01-01JQuery Tips(2) 關(guān)于$()包裝集你不知道的
包裝集總是面向集合的,需要的朋友可以參考下。2009-12-12