小程序實現抽獎動畫
更新時間:2020年04月16日 15:28:30 作者:qiphon3650
這篇文章主要為大家詳細介紹了小程序實現抽獎動畫,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了小程序實現抽獎動畫展示的具體代碼,供大家參考,具體內容如下
所有的抽獎都是由后臺計算后得到的,前臺只做動畫展示
<view class='top-banner center'> <!-- 輪播展示中獎信息區(qū)域 -->
<swiper autoplay="{{true}}" interval="{{1500}}" circular="{{true}}" vertical='{{true}}'>
<block wx:for="{{prizeInfo}}" wx:key="index">
<swiper-item>
<view>{{item.name}}{{item.prize}}</view>
</swiper-item>
</block>
</swiper>
</view>
<!-- 輪播結束 抽獎轉盤 -->
<view class='turntable' bindtap='doLottery'>
<image class='turntable-bj' style="transition:all {{time?time:'3s ease-in'}}; transform:rotate({{transformDeg + 'deg'}}) " src='../../../img/turntable.png'></image>
<image class='arrow' src='../../../img/arrow.png'>
</image>
</view>
js:
const app = getApp();
var index = {
data:{
prizeInfo:[
{
name:'qiphon',
prize:'5元'
},
{
name:'qiphon23423',
prize:'53元'
},
{
name:'qipsdfhon',
prize:'35元'
}
],
transformDeg:0, // 旋轉角度
transition:'all 3s cubic-bezier(0.005, 1.340, 1.000, 0.865)',
time:'999s'
},
onLoad(opt){
console.log(opt)
},
onReady(){
this.animation = wx.createAnimation({
timingFunction:'esse-in-out',
duration:2000
});
this.animationDeg = 360;
},
loadCoupons(){ // 加載獲獎信息
},
doLottery(){ // 抽獎
var _this = this;
if(this.aniRotate)return;
this.aniRotate = true;
this.setData({
transformDeg:this.data.transformDeg + 360*900,
time:'100s ease'
})
setTimeout(function(){
console.log('請求完成'+_this.data.transformDeg) // setTimeout 模擬ajax請求
_this.setData({
transformDeg:-360*4,
time:'3s ease'
})
setTimeout(function(){
console.log('返回結果'+_this.data.transformDeg)
_this.setData({
transformDeg:360*2 + 0,
time:'6s cubic-bezier(0.000, 0.765, 0.000, 0.955)'
})
setTimeout(function(){
_this.aniRotate = false;
wx.showModal({
title:'中獎信息',
content:'恭喜獲得獎品'
})
},6000)
},2000)
},3000)
},
}
Page(index);
css:
.top-banner{
background: #fff;
padding:20rpx;
}
.top-banner swiper{
height: 50rpx;
line-height: 50rpx;
}
/* 轉盤 */
.turntable{
position: relative;
width: 100%;
height: 530rpx;
}
.turntable-bj{
display: block;
margin:0 auto;
width:600rpx;
height: 530rpx;
}
.turntable .arrow{
position: absolute;
top:0;
right:0;
left:0;
bottom:110rpx;
margin:auto;
width:93.5rpx;
height: 212rpx;
}
想要學習更多關于抽獎功能的實現,請參考此專題:抽獎功能
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
網絡之美 JavaScript中Get和Set訪問器的實現代碼
前兩天IE9 Beta版發(fā)布了,對于從事Web開發(fā)的朋友們來說真是個好消息啊,希望將來有一天各個瀏覽器都能遵循統(tǒng)一的標準。今天要和大家分享的是JavaScript中的Get和Set訪問器,和C#中的訪問器非常相似。2010-09-09
JS使用oumousemove和oumouseout動態(tài)改變圖片顯示的方法
這篇文章主要介紹了JS使用oumousemove和oumouseout動態(tài)改變圖片顯示的方法,涉及javascript鼠標事件及圖片操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03
JavaScript和ActionScript的交互實現代碼
JavaScript和ActionScript的交互實現代碼,需要js與flash交互的朋友可以學習下。2010-08-08
javascript中不易分清的slice,splice和split三個函數
這篇文章主要為大家詳細介紹了javascript中不易分清的slice,splice和split三個函數,感興趣的小伙伴們可以參考一下2016-03-03

