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);
			},
相关推荐
烂蜻蜓24 分钟前
深入理解 Uniapp 中的 px 与 rpx
前端·css·vue.js·uni-app·html
狂团商城小师妹24 分钟前
智慧废品回收小程序php+uniapp
大数据·微信·微信小程序·小程序·uni-app·微信公众平台
烂蜻蜓1 小时前
Uniapp 中布局魔法:display 属性
前端·javascript·css·vue.js·uni-app·html
毕业设计-012 小时前
0083.基于springboot+uni-app的社区车位租赁系统小程序+论文
spring boot·小程序·uni-app
九亿少女无法触及的梦ى10 小时前
uni-app集成sqlite
sqlite·uni-app
繁依Fanyi11 小时前
巧妙实现右键菜单功能,提升用户操作体验
开发语言·前端·javascript·vue.js·uni-app·harmonyos
乔冠宇1 天前
微信小程序修改个人信息头像(uniapp开发)
微信小程序·小程序·uni-app
一个处女座的程序猿O(∩_∩)O1 天前
Uniapp 开发中遇到的坑与注意事项:全面指南
uni-app
Elena_Lucky_baby1 天前
uniapp 网络请求封装(uni.request 与 uView-Plus)
uni-app