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);
			},
相关推荐
橘子编程1 天前
UniApp跨端开发终极指南
开发语言·vue.js·uni-app
叱咤少帅(少帅)4 天前
Uniapp开发pc端,小程序和APK
小程序·uni-app
2501_915918414 天前
iOS性能测试工具 Instruments、Keymob的使用方法 不局限 FPS
android·ios·小程序·https·uni-app·iphone·webview
2501_915918414 天前
iOS 混淆流程 提升 IPA 分析难度 实现 IPA 深度加固
android·ios·小程序·https·uni-app·iphone·webview
前端 贾公子5 天前
解决uni-app 输入框,键盘弹起时页面整体上移问题
前端·vue.js·uni-app
Muchen灬5 天前
【uniapp】(5) 创建gitee仓库并推送源码
gitee·uni-app
Muchen灬5 天前
【uniapp】(6) uniapp中使用vuex
uni-app
2501_915909065 天前
React Native 上架 App Store:项目运行与审核构建的流程
android·ios·小程序·https·uni-app·iphone·webview
李庆政3705 天前
uniapp+unicloud打包部署微信小程序
微信小程序·小程序·uni-app