国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

jquery實(shí)現(xiàn)轉(zhuǎn)盤(pán)抽獎(jiǎng)功能

2019-11-19 18:05:30
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

實(shí)現(xiàn)這個(gè)其實(shí)蠻簡(jiǎn)單的,轉(zhuǎn)動(dòng)的效果用的jqueryRotate插件,所以只要判斷每個(gè)獎(jiǎng)薦對(duì)應(yīng)的角度,然后設(shè)置指針的轉(zhuǎn)動(dòng)角度就可以了。比如關(guān)鍵的是jqueryRotate這個(gè)插件的用法。

jqueryRotate的資料:

支持Internet Explorer 6.0+ 、Firefox 2.0 、Safari 3 、Opera 9 、Google Chrome,高級(jí)瀏覽器下使用Transform,低版本ie使用VML實(shí)現(xiàn)

google code地址:http://code.google.com/p/jqueryrotate/

調(diào)用和方法:

$(el).rotate({      angle:0, //起始角度     animateTo:180, //結(jié)束的角度     duration:500, //轉(zhuǎn)動(dòng)時(shí)間     callback:function(){}, //回調(diào)函數(shù)     easing: $.easing.easeInOutExpo //定義運(yùn)動(dòng)的效果,需要引用jquery.easing.min.js的文件  })$(el).rotate(45); //直接這樣子調(diào)用的話就是變換角度$(el).getRotateAngle(); //返回對(duì)象當(dāng)前的角度$(el).stopRotare(); //停止旋轉(zhuǎn)動(dòng)畫(huà)

另外可以更方便的通過(guò)調(diào)用$(el).rotateRight()和$(el).rotateLeft()來(lái)分別向右旋轉(zhuǎn)90度和向左旋轉(zhuǎn)90度。

很簡(jiǎn)單吧,各種example可以看這里:http://code.google.com/p/jqueryrotate/wiki/Examples

下面是用jqueryRotate實(shí)現(xiàn)的抽獎(jiǎng)轉(zhuǎn)盤(pán)頁(yè)面:

<!doctype html><html><head><meta charset="utf-8"><title>轉(zhuǎn)盤(pá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í)函數(shù) $("#lotteryBtn").rotate({  angle:0,   duration: 10000,   animateTo: 2160, //這里是設(shè)置請(qǐng)求超時(shí)后返回的角度,所以應(yīng)該還是回到最原始的位置,2160是因?yàn)槲乙屗D(zhuǎn)6圈,就是360*6得來(lái)的  callback:function(){  alert('網(wǎng)絡(luò)超時(shí)')  } });  };  var rotateFunc = function(awards,angle,text){ //awards:獎(jiǎng)項(xiàng),angle:獎(jiǎng)項(xiàng)對(duì)應(yīng)的角度,text:提示文字 $('#lotteryBtn').stopRotate(); $("#lotteryBtn").rotate({  angle:0,   duration: 5000,   animateTo: angle+1440, //angle是圖片上各獎(jiǎng)項(xiàng)對(duì)應(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ò)超時(shí)  }  if(time==1){   var data = [1,2,3,0]; //返回的數(shù)組   data = data[Math.floor(Math.random()*data.length)];   if(data==1){   rotateFunc(1,157,'恭喜您抽中的一等獎(jiǎng)')   }   if(data==2){   rotateFunc(2,247,'恭喜您抽中的二等獎(jiǎng)')   }   if(data==3){   rotateFunc(3,22,'恭喜您抽中的三等獎(jiǎng)')   }   if(data==0){   var angle = [67,112,202,292,337];    angle = angle[Math.floor(Math.random()*angle.length)]   rotateFunc(0,angle,'很遺憾,這次您未抽中獎(jiǎng)')   }  }  }  }  });})</script></html>

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持武林網(wǎng)!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 辽源市| 日照市| 屏东市| 宁波市| 临泽县| 左权县| 天峨县| 泰宁县| 易门县| 韶山市| 安溪县| 嘉祥县| 凤凰县| 浪卡子县| 鸡西市| 莒南县| 乌兰察布市| 浏阳市| 县级市| 平塘县| 龙游县| 齐齐哈尔市| 伊通| 贵定县| 内乡县| 沁源县| 安化县| 抚远县| 德州市| 枝江市| 大方县| 称多县| 阳泉市| 本溪市| 阿拉善右旗| 湖州市| 弥渡县| 商都县| 屏东市| 湟中县| 界首市|