手扣 大转盘抽奖

在这里插入图片描述
代码部分

<view class="container1">
			<view class="head-box">
			 
				<image src="../../../static/active/bigzp/qdcj-m1.png" mode="widthFix"></image>
			</view>
			<view class="bigdzp">
			
			    //大转盘背景图
				<image src="../../../static/active/bigzp/zm-zuanbg.png" mode="widthFix"></image>
				<view class="price-list" >
				//大转盘奖品图 奖品 0开始逆时针排序
					<image ref="dzp" id="bigzp" class="" src="../../../static/active/bigzp//qdcj-m2.png" mode="widthFix"></image>
				</view>
				//按钮
				<image class="btn" @click="ratating(“奖品排列数”,“提示”’)" src="../../../static/active/bigzp/play-btn.png" mode="widthFix">            </image>
			</view>
</view>
js部分
getRandom(n,m){             //该方法产生[n,m]之间随机数
			    let result = Math.floor(Math.floor(Math.random()*(m-n+1)+n))
			    return result;
			},  
ratating(deg,text){
			      this.goTimes -- //抽奖次数
			      this.isGo = true
				  let time_fw = this.getRandom(-0.5*360/‘奖品数量’,0.5*360/‘奖品数量’)// 让指针在中奖奖品区域随机停止
			      let times = this.getRandom(3,6)//圈数(从用户体验角度考虑,设计随机转3-6圈。最少3圈,最多6圈)
			      this.randomDeg =  (deg-1)*360/‘奖品数量’ + 360 * times+time_fw      //记录这次要旋转的度数(传来的度数+圈数)
			      let realDeg = (360 - this.lastDeg % 360) + this.lastDeg + this.randomDeg 
			      /*上次指针离初始状态的度数 + 上次的度数 + 这次要旋转的度数
			      (这样的目的是为了每次旋转都从原点开始,保证数据准确)*/
				  let domdzp = document.getElementById('bigzp');
				  console.log(deg,realDeg)
			      domdzp.style.transform = `rotate(${realDeg}deg)`;
			      setTimeout(() => {
			        this.isGo = false
			        console.log(`以原点为基准共旋转了${this.randomDeg}度,
			        			以一圈为基准相对旋转了${this.randomDeg % 360}度,最终结果为${text}`)
			        this.lastDeg = realDeg    //把这次度数存储起来,方便下一次获取
			      },4000)                     //4000ms为css里面写的执行动画的时间
			},  			
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值