• 【小程序】九宫格抽奖,页面不是有点丑,功能没啥问题,有需要直接拿去改吧


    概述

    常用活动抽奖功能,九宫格抽奖,两种方式切换,图片模式和文字模式,带抽奖次数。功能没啥问题,除了有点丑,css样式自己美化一下就可以了...

    详细

    微信小程序大转盘抽奖

    演示图文字:

    1625118073679.gif

    演示图 图片:

    1625118363790.gif

    部分代码:

    1. //获取应用实例
    2. var app = getApp()
    3. Page({
    4. data: {
    5. circleList: [],//圆点数组
    6. awardList: [],//奖品数组
    7. colorCircleFirst: '#FFDF2F',//圆点颜色1
    8. colorCircleSecond: '#FE4D32',//圆点颜色2
    9. colorAwardDefault: '#F5F0FC',//奖品默认颜色
    10. colorAwardSelect: '#000000',//奖品选中颜色
    11. indexSelect: 0,//被选中的奖品index
    12. isRunning: false,//是否正在抽奖
    13. lawNum:10,
    14. imageAward: [
    15. '../../images/1.jpg',
    16. '../../images/2.jpg',
    17. '../../images/3.jpg',
    18. '../../images/4.jpg',
    19. '../../images/5.jpg',
    20. '../../images/6.jpg',
    21. '../../images/7.jpg',
    22. '../../images/8.jpg',
    23. ],//奖品图片数组
    24. textAward: [
    25. '10元',
    26. '5元',
    27. '1元',
    28. '0.5元',
    29. '40元',
    30. '30元',
    31. '90元',
    32. '0.1元',
    33. ],//奖品图片数组
    34. isImage:true,
    35. },
    36. onLoad: function () {
    37. var _this = this;
    38. //圆点设置
    39. var leftCircle = 7.5;
    40. var topCircle = 7.5;
    41. var circleList = [];
    42. for (var i = 0; i < 24; i++) {
    43. if (i == 0) {
    44. topCircle = 15;
    45. leftCircle = 15;
    46. } else if (i < 6) {
    47. topCircle = 7.5;
    48. leftCircle = leftCircle + 102.5;
    49. } else if (i == 6) {
    50. topCircle = 15
    51. leftCircle = 620;
    52. } else if (i < 12) {
    53. topCircle = topCircle + 94;
    54. leftCircle = 620;
    55. } else if (i == 12) {
    56. topCircle = 565;
    57. leftCircle = 620;
    58. } else if (i < 18) {
    59. topCircle = 570;
    60. leftCircle = leftCircle - 102.5;
    61. } else if (i == 18) {
    62. topCircle = 565;
    63. leftCircle = 15;
    64. } else if (i < 24) {
    65. topCircle = topCircle - 94;
    66. leftCircle = 7.5;
    67. } else {
    68. return
    69. }
    70. circleList.push({ topCircle: topCircle, leftCircle: leftCircle });
    71. }
    72. this.setData({
    73. circleList: circleList
    74. })
    75. //圆点闪烁
    76. setInterval(function () {
    77. if (_this.data.colorCircleFirst == '#FFDF2F') {
    78. _this.setData({
    79. colorCircleFirst: '#FE4D32',
    80. colorCircleSecond: '#FFDF2F',
    81. })
    82. } else {
    83. _this.setData({
    84. colorCircleFirst: '#FFDF2F',
    85. colorCircleSecond: '#FE4D32',
    86. })
    87. }
    88. }, 500)
    89. //奖品item设置
    90. var awardList = [];
    91. //间距,怎么顺眼怎么设置吧.
    92. var topAward = 25;
    93. var leftAward = 25;
    94. for (var j = 0; j < 8; j++) {
    95. if (j == 0) {
    96. topAward = 25;
    97. leftAward = 25;
    98. } else if (j < 3) {
    99. topAward = topAward;
    100. //166.6666是宽.15是间距.下同
    101. leftAward = leftAward + 166.6666 + 15;
    102. } else if (j < 5) {
    103. leftAward = leftAward;
    104. //150是高,15是间距,下同
    105. topAward = topAward + 150 + 15;
    106. } else if (j < 7) {
    107. leftAward = leftAward - 166.6666 - 15;
    108. topAward = topAward;
    109. } else if (j < 8) {
    110. leftAward = leftAward;
    111. topAward = topAward - 150 - 15;
    112. }
    113. var imageAward;
    114. if(this.data.isImage){
    115. imageAward = this.data.imageAward[j];
    116. }else{
    117. imageAward = this.data.textAward[j];
    118. }
    119. awardList.push({ topAward: topAward, leftAward: leftAward, imageAward: imageAward });
    120. }
    121. this.setData({
    122. awardList: awardList
    123. })
    124. },
    125. //开始游戏
    126. startGame: function () {
    127. if (this.data.isRunning) return
    128. if(this.data.lawNum<=0){
    129. wx.showModal({
    130. content: '没有更多次数了',
    131. showCancel: false,//去掉取消按钮
    132. success: function (res) {
    133. if (res.confirm) {
    134. _this.setData({
    135. isRunning: false
    136. })
    137. }
    138. }
    139. })
    140. return
    141. }
    142. let num = this.data.lawNum
    143. this.setData({
    144. isRunning: true,
    145. lawNum:num
    146. })
    147. var _this = this;
    148. var indexSelect = 0
    149. var i = 0;
    150. var timer = setInterval(function () {
    151. indexSelect++;
    152. //这里我只是简单粗暴用y=30*x+200函数做的处理.可根据自己的需求改变转盘速度
    153. i += 30;
    154. if (i > 1000) {
    155. //去除循环
    156. clearInterval(timer)
    157. //获奖提示
    158. wx.showModal({
    159. title: '恭喜您',
    160. content: '获得了第' + (_this.data.indexSelect + 1) + "个优惠券",
    161. showCancel: false,//去掉取消按钮
    162. success: function (res) {
    163. if (res.confirm) {
    164. _this.setData({
    165. isRunning: false
    166. })
    167. }
    168. }
    169. })
    170. }
    171. indexSelect = indexSelect % 8;
    172. _this.setData({
    173. indexSelect: indexSelect
    174. })
    175. }, (200 + i))
    176. }
    177. })

    项目结构图:

    image.png

  • 相关阅读:
    Bean 作用域和生命周期
    Java面试题以及答案(六)Jvm
    线上环境内存溢出-OutOfMemoryError
    安全渗透测试基础知识之网络基础知识
    一种多媒体框架中的零buffer拷贝实现机制
    【技术分享】NetLogon于域内提权漏洞(CVE-2020-1472)
    使用Golong轻松实现JWT身份验证
    【C++】class的设计与使用(九)自定义函数对象(function object)
    Apollo 应用与源码分析:Monitor监控-软件监控-时间延迟监控
    【2022黑色星期五】5个有效的方法让客户打开您的电子邮件营销
  • 原文地址:https://blog.csdn.net/hanjiepo/article/details/133026130