欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2017年01月06日 16:58:57   作者:鏡子-正衣冠-知得失  
本文主要介紹了用的jqueryRotate插件實(shí)現(xiàn)轉(zhuǎn)盤(pán)抽獎(jiǎng)功能的方法,具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧

實(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í)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論