本文实例为大家分享了微信小程序实现转盘抽奖的具体代码,供大家参考,具体内容如下
效果图如下所示
.wxml
<view class="index">
 <view class="xian"></view>
 <view class="xian"></view>
 <view class="xian"></view>
 <view class="detail">一等奖</view>
 <view class="detail">二等奖</view>
 <view class="detail">三等奖</view>
 <view class="detail">四等奖</view>
 <view class="detail">五等奖</view>
 <view class="detail">六等奖</view>
 <span bindtap="zhuanin" style="transform:rotate({{trasn}}deg);"></span>
</view>
.wxss
.index{
 width: 300px;
 margin: 50rpx calc((100% - 300px) / 2);
 border:1px solid #ffcccc;
 border-radius: 50%;
 height: 300px;
 position: relative;
 overflow: hidden;
 font-size: 26rpx;
}
.xian{
 width:300px;
 height:1px;
 background:#d6d6d6;
 position:absolute;
 top:150px;
 left:0;
}
.index>.xian:nth-child(2){
 transform:rotateZ(60deg)
}
.index>.xian:nth-child(3){
 transform:rotateZ(120deg)
}
.detail{
 position: absolute;
}
.index>.detail:nth-child(4){
 top:25px;left:132px;
}
.index>.detail:nth-child(5){
 top:90px;left:225px;
}
.index>.detail:nth-child(6){
 top:190px;left:225px;
}
.index>.detail:nth-child(7){
 top:250px;left:132px;
}
.index>.detail:nth-child(8){
 top:190px;left:40px;
}
.index>.detail:nth-child(9){
 top:90px;left:40px;
}
.index>span{
 width: 30px;
 height: 30px;
 background-color: #ffcccc;
 border-radius: 50%;
 position: absolute;
 left: 135px;
 top:135px;
}
.index>span::after{
 content: ' ';
 width:0;
 height:0;
 border-right:6px solid transparent;
 border-left:6px solid transparent;
 border-bottom:26px solid #ffcccc;
 z-index: 10;
 position: absolute;
 left: 8.5px;
 top: -24px;
}
.js
Page({
 data: {
 random:'',
 trasn:0,
 },
 zhuanin:function(e){
 let that = this
 let num = 0
 that.setData({
  random:Math.floor(Math.random() * 360),
  trasn:0,
 })
 let a = setInterval(function () {
  that.setData({
  trasn:that.data.trasn+5
  })
  if(360 <= that.data.trasn){
  that.data.trasn = 0
  num = num + 1
  }
  if(num == 3){
  that.currinl()
  clearInterval(a)
  }
 },5)
 },
 currinl:function(e){
 let that = this
 let name = ''
 if(that.data.random == 30 || that.data.random == 90 || that.data.random == 150 || that.data.random == 210 || that.data.random == 330){
  that.setData({
  random:that.data.random + 1
  })
 }
 if(that.data.random < 30 || 330 < that.data.random){
  name = '一等奖'
 }else if(that.data.random > 30 && that.data.random < 90){
  name = '二等奖'
 }else if(that.data.random > 90 && that.data.random < 150){
  name = '三等奖'
 }else if(that.data.random > 150 && that.data.random < 210){
  name = '四等奖'
 }else if(that.data.random > 210 && that.data.random < 270){
  name = "五等奖"
 }else{
  name = "六等奖"
 }
 let b = setInterval(function () {
  that.setData({
  trasn:that.data.trasn+2
  })
  if(that.data.random <= that.data.trasn){
  wx.showToast({
   title: name,
   icon: 'none',
   duration: 2000
  })
  clearInterval(b)
  }
 },10)
 },
})
为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
                                    标签:
                                        
                            微信小程序,转盘抽奖
                                免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
                                如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
                            
                        暂无“微信小程序实现转盘抽奖”评论...
                                    更新动态
2025年10月31日
                                2025年10月31日
                    - 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
 
                         
                        