uniapp写抽奖转盘
生活随笔
收集整理的這篇文章主要介紹了
uniapp写抽奖转盘
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.今天寫一個(gè)抽獎(jiǎng)轉(zhuǎn)盤樣式如下,抽獎(jiǎng)結(jié)果由后端控制
2.代碼如下,
樣式如下:定位什么的可以自己調(diào)試
.choujiang{width:100%;height: 600rpx; }.wheel-wrapper {width: 600upx;height: 600upx;position: absolute;top: 60%;left: 50%;transform: translate(-50%, -50%); }.wheel-pointer {width: 150upx;height: 192upx;border-radius: 1000px;background: yellow;position: absolute;left: 50%;top: 61%;margin-top: -88upx;transform: translate(-50%, -50%);text-align: center;line-height: 120upx;z-index: 10; }.wheel-bg {width: 100%;height: 100%;border-radius: 1000px;overflow: hidden;transition: transform 4s ease-in-out;background: #dcdcdc; }.freeze {border-radius: 0;background: none;background-size: 100% !important; }.prize-list {width: 100%;height: 100%;position: relative;text-align: center; }.prize-item-wrapper {position: absolute;top: 0;left: 50%;transform: translateX(-50%);width: 300upx;height: 300upx; }.prize-item {width: 100%;height: 100%;transform-origin: bottom; }.prize-name {padding: 86upx 0 10upx;color: #E73636;font-size: 32rpx;font-weight: bold; }.prize-icon .iconhb {font-size: 50rpx;color: #FA4A4A; }3.在data里面進(jìn)行申明
data() {return {prizeList: [], //獎(jiǎng)品分類bgImg: '../../static/img/pan.png', // 轉(zhuǎn)盤背景btnImg: '../../static/img/zhen2.png', // 轉(zhuǎn)盤指針圖片lucky: '', // 中獎(jiǎng)IDprizeNumber: 8, // 轉(zhuǎn)盤顯示獎(jiǎng)品個(gè)數(shù)rolling: false, //控制轉(zhuǎn)盤轉(zhuǎn)動(dòng)wheelDeg: 0, //轉(zhuǎn)的角度} },4.寫事件
onClickRotate() {let that = this;//參數(shù)let data = {type: that.type,id: that.detail.id,}//接口,參考我寫的接口封裝,也可以用自己的辦法,主要的是接口請求成功后的操作that.apifun.unirequest(that.apifun.turntable_luckdraw, 'post', data, (res) => {if (res.code === 1) {let data = res.data;//后端返回的中獎(jiǎng)idthat.lucky = data.award;let luckyindex = '';let text = '恭喜得到' + data.award_title + data.memo;//為了轉(zhuǎn)盤停到指控區(qū)域,通過返回的中獎(jiǎng)id,在獎(jiǎng)品列表里面查找對應(yīng)的獎(jiǎng)項(xiàng)的索引that.prizeList.forEach((item, index) => {if (that.lucky == item.id) {luckyindex = index * 1;}})that.rolling = true; //中獎(jiǎng)成功,控制轉(zhuǎn)盤轉(zhuǎn)動(dòng)const {wheelDeg,prizeList} = this;//數(shù)字8是轉(zhuǎn)盤的塊數(shù)也是獎(jiǎng)項(xiàng)的數(shù)量,luckyindex中的獎(jiǎng)項(xiàng)的索引this.wheelDeg =wheelDeg -wheelDeg % 360 +8 * 360 +(360 - 360 / prizeList.length * luckyindex);//中獎(jiǎng)返回中獎(jiǎng)信息,this.apifun.toast(text);是封裝的提示,可以用uniapp的提示方法代替setTimeout(() => {this.rolling = false;this.apifun.toast(text);}, 4500);} else {that.apifun.toast(res.msg)}}) },總結(jié)
以上是生活随笔為你收集整理的uniapp写抽奖转盘的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 511遇见易语言去除数组里的重复成员
- 下一篇: 6G愿景与需求:数字孪生、智能泛在