uniapp 九宫格抽奖

抽奖

样式就自己写吧

实现思路:因为是九宫格,里面商品只会有九个,他们的index是固定的,然后根据后端返回的中奖商品id找出他的index,设置抽奖动画固定跑三遍然后加上你中奖id的index即可

代码:

// 点击后 true 获取奖品后 false 防止重复点击

rolling: false,

// 滚动选中的id

currentIdx: -1,

// 中奖id的key

prizeId: null

点击抽奖事件

复制代码
// 点击抽奖事件
			drawChange() {
				if (this.rolling) return
				this.currentIdx = -1
				this.rolling = true
				var id = 2
				// 根据key值所以加1
				this.prizeId = this.drawList.findIndex(item => item.id == id)
				if (this.prizeId < 0) {
					this.$Common.showToast('系统繁忙,请稍后重试')
				} else {
					this.prizeId += 1
					this.startAnimation()
				}
			},
			startAnimation() {
				let speed = 100; // 初始速度(ms)
				let step = 0;
				const totalSteps = 9 + this.prizeId; // 总滚动步数
				this.intervalId = setInterval(() => {
					if (step >= totalSteps) {
						clearInterval(this.intervalId);
						// 打开弹窗
						this.stopAtTarget();
					} else {
						this.currentIdx = (this.currentIdx + 1) % this.drawList.length;
						speed += 40; // 逐步增加间隔时间模拟减速
						step++;
					}
				}, speed);
			},
相关推荐
fakaifa1 小时前
【最新版】CRMEB Pro版v3.4系统源码全开源+PC端+uniapp前端+搭建教程
人工智能·小程序·uni-app·php·crmeb·源码下载·crmebpro
2501_915918418 小时前
iOS 应用上架全流程实践,从开发内测到正式发布的多工具组合方案
android·ios·小程序·https·uni-app·iphone·webview
梦里寻码15 小时前
自行食用 uniapp 多端 手写签名组件
前端·uni-app
不如摸鱼去1 天前
Trae 辅助下的 uni-app 跨端小程序工程化开发实践分享
微信小程序·小程序·uni-app·aigc·ai编程
小白_ysf2 天前
uniapp 开发微信小程序,获取经纬度并且转化详细地址(单独封装版本)
微信小程序·uni-app
iOS阿玮2 天前
三年期已满,你的产品不再更新将于90天后下架。
uni-app·app·apple
bug总结3 天前
深入理解 uni-app 的 uni.createSelectorQuery()
uni-app
真上帝的左手3 天前
25. 移动端-uni-app
uni-app
编程猪猪侠3 天前
基于Uni-app+vue3实现微信小程序地图固定中心点范围内拖拽选择位置功能(分步骤详解)
uni-app
小徐_23333 天前
Trae 辅助下的 uni-app 跨端小程序工程化开发实践分享
前端·uni-app·trae