当前位置: 首页 > article >正文

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);
			},


http://www.kler.cn/a/558886.html

相关文章:

  • QEMU源码全解析 —— 内存虚拟化(18)
  • NavVis VLX三维扫描:高层建筑数字化的革新力量【沪敖3D】
  • 【量化策略】均值回归策略
  • 基于CentOS7安装kubesphere和Kubernetes并接入外部ES收集日志
  • QString是 Qt 框架中的一个核心类,基本用法使用:创建、字符串拼接、截取、查找、替换、分割、大小写转换、比较。
  • jar、war、pom
  • C++ 设计模式 - 策略模式
  • 力扣hot100——LRU缓存(面试高频考题)
  • 单机上使用docker搭建minio集群
  • 如何使用Spring boot框架实现图书管理系统
  • Ollama API 交互
  • 20250223C语言指针与应用
  • Python爬虫具体是如何解析商品信息的?
  • MybatisPlus-注解
  • .NET8入门:13.ASP.NET Core MVC
  • AI客服-接入deepseek大模型到微信(本地部署deepseek集成微信自动收发消息)
  • ArcGIS Pro热力图制作指南:从基础到进阶
  • VS2022配置FFMPEG库基础教程
  • 视频mp4垂直拼接 水平拼接
  • Vulhub靶机 Apache Druid(CVE-2021-25646)(渗透测试详解)