废话不多说,先上样板图

代码就先wxml文件:

<view id="container"><!--左上--><view id="li" class='{{amplification_index===1?"indexli":""}}'>一等奖<view></view></view><!--上--><view id="li" class='{{amplification_index===2?"indexli":""}}'>二等奖<view></view></view><!--右上--><view id="li" class='{{amplification_index===3?"indexli":""}}'>三等奖<view></view></view><!--左--><view id="li" class='{{amplification_index===8?"indexli":""}}'>八等奖<view></view></view><!--开始--><a bindtap="startrolling">开始抽奖</a><!--右--><view id="li" class='{{amplification_index===4?"indexli":""}}'>四等奖<view></view></view><!--左下--><view id="li" class='{{amplification_index===7?"indexli":""}}'>七等奖<view></view></view><!--下--><view id="li" class='{{amplification_index===6?"indexli":""}}'>六等奖<view></view></view><!--右下--><view id="li" class='{{amplification_index===5?"indexli":""}}'>五等奖<view></view></view><p id="pp"></p>
</view>

wxss文件:

#container {width: 750rpx;height: 750rpx;
}#li, a {background: #fff;margin: 20rpx;border: 1px solid #000000;width: 210rpx;height: 210rpx;box-sizing: border-box;display: block;float: left;text-align: center;line-height: 100px;position: relative;border-radius: 5rpx;
}a:hover {cursor: pointer;color: orange;font-size: 18px;
}.active {background: red;color: #fff;
}#pp {line-height: 32px;color: #9a9a9a;text-align: center;
}page view .indexli {width: 210rpx;height: 210rpx;margin-top: 0rpx;margin-left: 0rpx;margin-bottom: 0rpx;margin-right: 0rpx;box-sizing: border-box;
}.indexli view {position: absolute;width: 190rpx;height: 190rpx;background: #000000;opacity: 0.3;left: 0;top: 0;border:10rpx solid blue;
}a {position: relative;
}a image {width: 100%;height: 100%;border-radius: 5rpx;
}a view {width: 80rpx;height: 80rpx;position: absolute;font-size: 40rpx;color: #fff;font-weight: 700;line-height: 40rpx;margin-left: -40rpx;margin-top: -40rpx;left: 50%;top: 50%;}.c_title {width: 100%;text-align: center;color: #fff;font-size: 20rpx;padding-top: 30rpx;
}.c_title2 {color: #fff;text-align: center;font-size: 40rpx;
}.c_title3 {background: red;width: 250rpx;margin-left: 250rpx;height: 40rpx;line-height: 40rpx;color: #fff;font-size: 20rpx;text-align: center;
}.c_titlr4 {background: gold;color: red;width: 400rpx;border-radius: 500rpx;text-align: center;font-size: 20rpx;margin-left: 175rpx;margin-top: 10rpx;
}.b1 {margin-left: 20rpx;

js文件

// pages/Lottery/Lottery.js
Page({data: {last_index: 0,//上一回滚动的位置amplification_index: 0,//轮盘的当前滚动位置roll_flag: true,//是否允许滚动max_number: 8,//轮盘的全部数量speed: 300,//速度,速度值越大,则越慢 初始化为300finalindex: 5,//最终的奖励距离当前的位置!不是最后的几等奖!myInterval: "",//定时器max_speed: 40,//滚盘的最大速度minturns: 8,//最小的圈数为2runs_now: 0//当前已跑步数},//开始滚动startrolling: function () {let _this = this;//初始化步数_this.data.runs_now = 0;//当前可以点击的状态下if (_this.data.roll_flag) {_this.data.roll_flag = false;//启动滚盘,注,若是最终后台无返回就不好意思里_this.rolling();}},onShow: function () {this.data.min_height = getApp().globalData.windowheight;this.setData(this.data);},//滚动轮盘的动画效果rolling: function (amplification_index) {var _this = this;this.data.myInterval = setTimeout(function () { _this.rolling(); }, this.data.speed);this.data.runs_now++;//已经跑步数加一this.data.amplification_index++;//当前的加一//获取总步数,接口延迟问题,所以最后还是设置成1s以上var count_num = this.data.minturns * this.data.max_number + this.data.finalindex - this.data.last_index;//上升期间if (this.data.runs_now <= (count_num / 3) * 2) {this.data.speed -= 30;//加速if (this.data.speed <= this.data.max_speed) {this.data.speed = this.data.max_speed;//最高速度为40;}}//抽奖结束else if (this.data.runs_now >= count_num) {clearInterval(this.data.myInterval);this.data.roll_flag = true;}//下降期间else if (count_num - this.data.runs_now <= 10) {this.data.speed += 20;}//缓冲区间else {this.data.speed += 10;if (this.data.speed >= 100) {this.data.speed = 100;//最低速度为100;}}if (this.data.amplification_index > this.data.max_number) {//判定!是否大于最大数this.data.amplification_index = 1;}this.setData(this.data);}
})

样式

color: #fff; font-size: 40rpx;}
.b2 { margin-left: 20rpx; color: #fff; font-size: 25rpx;}
.b3 { margin-left: 20rpx; color: #fff; font-size: 25rpx;}
.b4 { margin-left: 20rpx; color: #fff; font-size: 25rpx;}
.b5 { margin-left: 20rpx; color: #fff; font-size: 25rpx;}

微信小程序:九宫格抽奖相关推荐

  1. 【小程序与公众号】微信小程序九宫格抽奖(抽奖完全随机)

    上图 话不多说直接上图,抽奖是顺时针又快变慢(还原抽奖的动画)进行抽奖,抽奖的几率都是随机 源码 接下来展示的就是微信小程序中的九宫格抽奖 说明 适用范围 抽奖逻辑只是原生JS,通过数据进行驱动,因此 ...

  2. 微信小程序 九宫格抽奖

    因公司需求要做一个小程序的九宫格抽奖,但是一块又没有合适的插件,于是到网上看到一个,还挺不错的. 效果图 1.外面一圈闪烁的小球是用js控制的样式.500ms改变一次样式.简单粗暴; 2.抽奖的ite ...

  3. 微信小程序九宫格抽奖

    效果图比较卡顿,真实运行效果是旋转的 用到的素材: 实现步骤: 实现原理 改变每一项的透明度实现选中效果.利用setTimeOut时间使旋转速度越来越慢.达到慢慢停止的效果.实际应用中可以将9张奖品图 ...

  4. html 小程序九宫格抽奖,【小程序与公众号】微信小程序九宫格抽奖(抽奖完全随机)...

    let timer; let onDrawing = false; // 是否可进行抽奖标识,默认为false可进行抽奖 let drawIndex = 0; //抽奖过程KEY Component( ...

  5. IVX低代码平台开发——微信小程序实现抽奖功能

    写在前面 通过利用可视化编程实现微信小程序的抽奖功能,带大家初步了解 iVX 的强大之处. 文章目录 写在前面 iVX开发 抽奖功能实现 iVX开发 基本介绍 iVX是一个 "零代码&quo ...

  6. 微信小程序-转盘抽奖

    微信小程序-转盘抽奖代码: lucky-draw.wxss: .lucky_draw_zp{ width: 502rpx; height: 502rpx; margin: 0 auto; positi ...

  7. 微信小程序的抽奖页面

    微信小程序的抽奖页面 做一个1-10的微信小程序抽奖界面,随机到6和8会显示中奖信息! 点开始按钮开始执行,点结束按钮结束抽奖并且判断是否中奖 wxml代码: <view>{{title} ...

  8. 微信小程序九宫格图的排版----注意层次排版(层次最重要)

    微信小程序九宫格图的排版----注意层次排版(层次最重要) 1.wxml中的代码(图片和数据都是网页获取来的,详细下看) 2.排版 3.使用.js文件进行事件加载 | | | |

  9. 微信小程序圆盘抽奖(扇形画圆)

    微信小程序圆盘抽奖(扇形画圆) 前言 提示:这里可以添加本文要记录的大概内容: 例如:领导安排做一个微信小程序的转盘抽奖,要求可以复用,动态的修改抽奖的板块个数,由于是第一次做微信小程序踩了很多的坑, ...

  10. html 小程序九宫格抽奖,微信小程序实现多宫格抽奖活动

    最近闲来无事,做了一个多宫格抽奖的例子,有什么需要改进或者错误的地方,请留言,谢谢 首先看效果: 思路是先让其转动2圈多,然后再进行抽奖,格子运动用的是setTimeout,让其运行的时间间隔不一样, ...

最新文章

  1. SAP S/4 HANA中的供应链计划提升
  2. oracle如何降低逻辑读,如何降低该SQL的逻辑读
  3. linux rpm安装不成功,rpm 包不能成功安装
  4. 大学计算机课感悟100字,停课不停学的心得100字 停课不停学的感想
  5. 使用mcisendstring重复播放音乐文件
  6. 锐起无盘找不到服务器,锐起无盘出现重启后连接不到服务器
  7. 歌德语言证书c1考什么,不完全不客观地比较三种德语考试——TestDaF德福、歌德C1、歌德C2...
  8. python高维数据可视化_【机器学习】(十六)主成分分析PCA:高维数据可视化、特征提取...
  9. JAVA在线考试系统毕业设计 开题报告
  10. 清华大学MOOC《操作系统》第1讲:“操作系统概述”总结(转)
  11. 计算机程序ppt,计算机和计算机程序.ppt
  12. python 三维曲线拟合_python实现三维拟合的方法
  13. 阿里CTO程立:科技公司的技术创新和责任担当
  14. C++课程设计(校车订票管理系统)
  15. Oracle select表要带双引号的原因
  16. 2018币圈热搜大事件汇总-千氪
  17. 外部访问docker容器(docker run -p/-P 指令)
  18. 你才诺基亚,你全家都是诺基亚
  19. 异性相吸_writeup
  20. 图像入门——1. 图像与数字图像介绍

热门文章

  1. 键盘输入,大写字母变小写,小写变大写
  2. DOM初探(15)——查看视口的尺寸
  3. 总结:Web3用户体验的四个层
  4. 权重初始化方法及适用情况
  5. 设计模式(工厂模式)
  6. vue项目无法在IE浏览器中显示
  7. 【NOI题库】【NOIP2016PJ猜题】雇佣兵
  8. 搭建个人网站---域名+解析+github
  9. esp32cam与android app的同步udp通信
  10. POJ - 1061 青蛙的约会