本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)抽獎(jiǎng)動(dòng)畫展示的具體代碼,供大家參考,具體內(nèi)容如下
所有的抽獎(jiǎng)都是由后臺(tái)計(jì)算后得到的,前臺(tái)只做動(dòng)畫展示
<view class='top-banner center'> <!-- 輪播展示中獎(jiǎng)信息區(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><!-- 輪播結(jié)束 抽獎(jiǎng)轉(zhuǎn)盤 --><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, // 旋轉(zhuǎn)角度 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(){ // 加載獲獎(jiǎng)信息 }, doLottery(){ // 抽獎(jiǎng) 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('請(qǐng)求完成'+_this.data.transformDeg) // setTimeout 模擬ajax請(qǐng)求 _this.setData({ transformDeg:-360*4, time:'3s ease' }) setTimeout(function(){ console.log('返回結(jié)果'+_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:'中獎(jiǎng)信息', content:'恭喜獲得獎(jiǎng)品' }) },6000) },2000) },3000) },}Page(index);
css:
.top-banner{ background: #fff; padding:20rpx;}.top-banner swiper{ height: 50rpx; line-height: 50rpx;}/* 轉(zhuǎn)盤 */.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;}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選