jquery實(shí)現(xiàn)轉(zhuǎn)盤抽獎(jiǎ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)畫
另外可以更方便的通過調(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)盤頁(yè)面:
<!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í)函數(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í)也希望多多支持腳本之家!
- jquery.rotate.js實(shí)現(xiàn)可選抽獎(jiǎng)次數(shù)和中獎(jiǎng)內(nèi)容的轉(zhuǎn)盤抽獎(jiǎng)代碼
- jquery 年會(huì)抽獎(jiǎng)程序
- jQuery實(shí)現(xiàn)轉(zhuǎn)動(dòng)隨機(jī)數(shù)抽獎(jiǎng)效果的方法
- jquery 抽獎(jiǎng)小程序?qū)崿F(xiàn)代碼
- jquery實(shí)現(xiàn)九宮格大轉(zhuǎn)盤抽獎(jiǎng)
- jQuery實(shí)現(xiàn)類似老虎機(jī)滾動(dòng)抽獎(jiǎng)效果
- jquery輸入數(shù)字隨機(jī)抽獎(jiǎng)特效的簡(jiǎn)單實(shí)現(xiàn)代碼
- jquery——九宮格大轉(zhuǎn)盤抽獎(jiǎng)實(shí)例
- jQuery+PHP實(shí)現(xiàn)的擲色子抽獎(jiǎng)游戲?qū)嵗?/a>
- jQuery實(shí)現(xiàn)移動(dòng)端扭蛋機(jī)抽獎(jiǎng)
相關(guān)文章
jQuery實(shí)現(xiàn)移動(dòng)端懸浮拖動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)移動(dòng)端懸浮拖動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
基于jQuery實(shí)現(xiàn)選項(xiàng)卡效果
這篇文章主要為大家詳細(xì)介紹了基于jQuery實(shí)現(xiàn)選項(xiàng)卡效果的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
jQuery插件之Tocify動(dòng)態(tài)節(jié)點(diǎn)目錄菜單生成器附源碼下載
Tocify是一個(gè)能夠動(dòng)態(tài)生成文章節(jié)點(diǎn)目錄的jQuery插件,通過本文給大家分享jQuery插件之Tocify動(dòng)態(tài)節(jié)點(diǎn)目錄菜單生成器,對(duì)tocify菜單生成器相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-01-01
JQuery Tips(2) 關(guān)于$()包裝集你不知道的
包裝集總是面向集合的,需要的朋友可以參考下。2009-12-12
jQuery內(nèi)容選擇器與表單選擇器實(shí)例分析
這篇文章主要介紹了jQuery內(nèi)容選擇器與表單選擇器,結(jié)合實(shí)例形式分析了jQuery內(nèi)容選擇器與表單選擇器的功能、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-06-06
jQuery實(shí)現(xiàn)單行文字間歇向上滾動(dòng)源代碼
使用jquery實(shí)現(xiàn)的文字向上滾動(dòng)效果多的不計(jì)其數(shù)吧,間歇向上滾動(dòng)卻不是那么的多,所以本文簡(jiǎn)單的實(shí)現(xiàn)了一個(gè),感興趣的朋友可以參考下哈2013-06-06
jQuery實(shí)現(xiàn)給input綁定回車事件的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)給input綁定回車事件的方法,結(jié)合實(shí)例形式分析了2種常用的事件綁定操作技巧,需要的朋友可以參考下2017-02-02
JQuery創(chuàng)建DOM節(jié)點(diǎn)的方法
這篇文章主要介紹了JQuery創(chuàng)建DOM節(jié)點(diǎn)的方法,實(shí)例分析了jQuery創(chuàng)建元素結(jié)點(diǎn)、文本結(jié)點(diǎn)、屬性結(jié)點(diǎn)的相關(guān)技巧,需要的朋友可以參考下2015-06-06

