小程序制作扭蛋机

2019-09-24 13:26:53

公司要制作活动小程序,其中有一个扭蛋机的效果实现抽奖的功能。在网上找了好久竟没有找到(不知道是不是我找代码的方式有问题)。最后还是自己做一个吧- _ - ,效果如下:

1.wxml

当然我这里没有用wx:for遍历

  1. <!-- 扭蛋机 -->
  2. <view class="egg">
  3. <image class="egg_ji" src="{{imgUrl}}small_program/game/game_luck_draw_nd.png" mode="widthFix"></image>
  4. <image class="play {{start?'go':''}}" bindtap="eggPlay" src="{{imgUrl}}small_program/game/game_luck_draw_eggplay.png" mode="widthFix"></image>
  5. <image class="ball ball_1 {{start?'weiyi_1':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg1.png" mode="widthFix"></image>
  6. <image class="ball ball_2 {{start?'weiyi_2':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg2.png" mode="widthFix"></image>
  7. <image class="ball ball_3 {{start?'weiyi_3':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg3.png" mode="widthFix"></image>
  8. <image class="ball ball_4 {{start?'weiyi_4':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg4.png" mode="widthFix"></image>
  9. <image class="ball ball_5 {{start?'weiyi_5':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg5.png" mode="widthFix"></image>
  10. <image class="ball ball_6 {{start?'weiyi_6':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg6.png" mode="widthFix"></image>
  11. <image class="ball ball_7 {{start?'weiyi_7':''}}" src="{{imgUrl}}small_program/game/game_luck_draw_egg7.png" mode="widthFix"></image>
  12. <image hidden="{{qiu}}" animation="{{ani}}" class="ball ball_end" src="{{imgUrl}}small_program/game/game_luck_draw_egg7.png" mode="widthFix" ></image>
  13. </view>

2.wxss

这一步比较麻烦,需要调试扭蛋的位置和动画路径

  1. /* 扭蛋机 */
  2. .egg{
  3. width: %;
  4. position: absolute;
  5. z-index: ;
  6. top: 260rpx;
  7. }
  8. .egg .egg_ji{
  9. width: %;
  10. margin-left: %;
  11. z-index: ;
  12. }
  13. .egg .play{
  14. width: 80rpx;
  15. position: absolute;
  16. z-index: ;
  17. top: 405rpx;
  18. left: 275rpx;
  19. }
  20. .egg .ball{
  21. width: 75rpx;
  22. position: absolute;
  23. z-index: ;
  24. }
  25. .egg .ball_1{
  26. top: 290rpx;
  27. left: 300rpx;
  28. }
  29. .egg .ball_2{
  30. top: 295rpx;
  31. left: 360rpx;
  32. }
  33. .egg .ball_3{
  34. top: 260rpx;
  35. left: 240rpx;
  36. }
  37. .egg .ball_4{
  38. top: 260rpx;
  39. left: 420rpx;
  40. }
  41. .egg .ball_5{
  42. top: 230rpx;
  43. left: 280rpx;
  44. }
  45. .egg .ball_6{
  46. top: 230rpx;
  47. left: 340rpx;
  48. }
  49. .egg .ball_7{
  50. top: 220rpx;
  51. left: 390rpx;
  52. }
  53. .egg .ball_end{
  54. top: 410rpx;
  55. left: 390rpx;
  56. }
  57.  
  58. .weiyi_1 {
  59. animation: around1 .5s linear infinite;
  60. }
  61. .weiyi_2 {
  62. animation: around2 .5s linear infinite;
  63. }
  64. .weiyi_3 {
  65. animation: around3 .5s linear infinite;
  66. }
  67. .weiyi_4 {
  68. animation: around4 .5s linear infinite;
  69. }
  70. .weiyi_5 {
  71. animation: around5 .5s linear infinite;
  72. }
  73. .weiyi_6 {
  74. animation: around6 .5s linear infinite;
  75. }
  76. .weiyi_7 {
  77. animation: around7 .5s linear infinite;
  78. }
  79. .go{
  80. animation: around .3s linear ;
  81. }
  82.  
  83. /* 位移 */
  84. @keyframes around{
  85. % {
  86. -webkit-transform: rotate(-180deg)
  87. }
  88. }
  89.  
  90. @keyframes around1 {
  91. % {
  92. -webkit-transform: translate(0rpx, 0rpx)
  93. }
  94. % {
  95. -webkit-transform: translate(-100rpx, -200rpx)
  96. }
  97. % {
  98. -webkit-transform: translate(40rpx, -280rpx)
  99. }
  100. % {
  101. -webkit-transform: translate(150rpx, -200rpx)
  102. }
  103. % {
  104. -webkit-transform: translate(150rpx, -50rpx)
  105. }
  106. % {
  107. -webkit-transform: translate(, )
  108. }
  109. }
  110.  
  111. @keyframes around2 {
  112. % {
  113. -webkit-transform: translate(0rpx, 0rpx)
  114. }
  115. % {
  116. -webkit-transform: translate(100rpx, -200rpx)
  117. }
  118. % {
  119. -webkit-transform: translate(-20rpx, -280rpx)
  120. }
  121. % {
  122. -webkit-transform: translate(-150rpx, -200rpx)
  123. }
  124. % {
  125. -webkit-transform: translate(-150rpx, -50rpx)
  126. }
  127. % {
  128. -webkit-transform: translate(, )
  129. }
  130. }
  131.  
  132. @keyframes around3 {
  133. % {
  134. -webkit-transform: translate(0rpx, 0rpx)
  135. }
  136. % {
  137. -webkit-transform: translate(180rpx, 10rpx)
  138. }
  139. % {
  140. -webkit-transform: translate(240rpx, -110rpx)
  141. }
  142. % {
  143. -webkit-transform: translate(100rpx, -240rpx)
  144. }
  145. % {
  146. -webkit-transform: translate(-50rpx, -130rpx)
  147. }
  148. % {
  149. -webkit-transform: translate(, )
  150. }
  151. }
  152.  
  153. @keyframes around4 {
  154. % {
  155. -webkit-transform: translate(0rpx, 0rpx)
  156. }
  157. % {
  158. -webkit-transform: translate(-180rpx, 10rpx)
  159. }
  160. % {
  161. -webkit-transform: translate(-240rpx, -110rpx)
  162. }
  163. % {
  164. -webkit-transform: translate(-100rpx, -240rpx)
  165. }
  166. % {
  167. -webkit-transform: translate(50rpx, -130rpx)
  168. }
  169. % {
  170. -webkit-transform: translate(, )
  171. }
  172. }
  173.  
  174. @keyframes around5 {
  175. % {
  176. -webkit-transform: translate(0rpx, 0rpx)
  177. }
  178. % {
  179. -webkit-transform: translate(40rpx, 70rpx)
  180. }
  181. % {
  182. -webkit-transform: translate(50rpx, -210rpx)
  183. }
  184. % {
  185. -webkit-transform: translate(-80rpx, -100rpx)
  186. }
  187. % {
  188. -webkit-transform: translate(190rpx, -50rpx)
  189. }
  190. % {
  191. -webkit-transform: translate(, )
  192. }
  193. }
  194.  
  195. @keyframes around6 {
  196. % {
  197. -webkit-transform: translate(0rpx, 0rpx)
  198. }
  199. % {
  200. -webkit-transform: translate(-150rpx, -50rpx)
  201. }
  202. % {
  203. -webkit-transform: translate(130rpx, -140rpx)
  204. }
  205. % {
  206. -webkit-transform: translate(-110rpx, -180rpx)
  207. }
  208. % {
  209. -webkit-transform: translate(-130rpx, -20rpx)
  210. }
  211. % {
  212. -webkit-transform: translate(, )
  213. }
  214. }
  215.  
  216. @keyframes around7 {
  217. % {
  218. -webkit-transform: translate(0rpx, 0rpx)
  219. }
  220. % {
  221. -webkit-transform: translate(80rpx, -50rpx)
  222. }
  223. % {
  224. -webkit-transform: translate(-180rpx, -100rpx)
  225. }
  226. % {
  227. -webkit-transform: translate(50rpx, -150rpx)
  228. }
  229. % {
  230. -webkit-transform: translate(-180rpx, -20rpx)
  231. }
  232. % {
  233. -webkit-transform: translate(, )
  234. }
  235. }

3.js

这一步要比css要是要简单的多,点击使动画动起来,调用api接口获取奖品就可以了

  1. Page({
  2.  
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. imgUrl: app.data.imgUrl,
  8. start : false,
  9. qiu: true,
  10. },
  11.  
  12. /**
  13. * 点击扭蛋机
  14. */
  15. eggPlay(){
  16. let _this = this;
  17.  
  18. _this.setData({
  19. start: true,
  20. })
  21. setTimeout(() => {
  22. _this.setData({
  23. start: false,
  24. qiu: false,
  25. })
  26. //球落下动画
  27. var animation = wx.createAnimation({
  28. duration: ,
  29. timingFunction: 'ease',
  30. });
  31. animation.opacity().step()
  32. this.setData({
  33. ani: animation.export()
  34. })
  35. }, );
  36.  
  37. _this.setData({
  38. qiu: true
  39. })
  40. //将动画返回到开始位置
  41. var animation = wx.createAnimation({
  42. duration: ,
  43. timingFunction: 'ease',
  44. });
  45. animation.opacity().step()
  46. this.setData({
  47. ani: animation.export()
  48. })
  49. },

这个动画有个小的bug,就是连续点击按钮动画时间会变快,如果有更好的方法可以留言交流。

微信小程序wxss制作扭蛋机的更多相关文章

  1. 微信小程序----wxss设置样式

    一.wxml 界面结构wxmL比较容易理解,主要是由八大类基础组件构成: 一.视图容器(View Container): 二.基础内容(Basic Content) 组件名 说明 组件名 说明 vie ...

  2. 微信小程序wxss设置样式

    微信小程序wxss设置样式 对于以前搞客户端开发的来说,有着客户端的逻辑,就是不知道怎么设置样式,把对应的控件显示出来 一.wxml 界面结构wxmL比较容易理解,主要是由八大类基础组件构成: 一.视 ...

  3. 微信小程序在线制作 自己制作微信小程序

    小程序是个什么东西?怎么自己制作微信小程序?微信小程序在线制作难吗?最近老是听这类问题,耳朵都长茧子了. 百牛信息技术bainiu.ltd整理发布于博客园 接下来作为一个技术人员的角度就为大家分析一下 ...

  4. 微信小程序wxss样式详解

    一.wxml 界面结构wxmL比较容易理解,主要是由八大类基础组件构成: 一.视图容器(View Container): 二.基础内容(Basic Content) 组件名 说明 组件名 说明 vie ...

  5. 微信小程序swiper制作内容高度不定的tab选项卡

    微信小程序利用swiper制作内容高度不定的tab选项卡,不使用absolute定位,不定高度,由内容自由撑开主要思路是获取内容区的高度来给swiper动态设置值 .wxml <view cla ...

  6. 微信小程序-从零开始制作一个跑步微信小程序

    来源:伯乐在线 - 王小树 链接:http://ios.jobbole.com/90603/ 点击 → 申请加入伯乐在线专栏作者 一.准备工作 1.注册一个小程序账号,得用一个没注册过公众号的邮箱注册 ...

  7. 微信小程序,制作属于自己的Icon图标

    前言 最近在接手一个微信小程序,发现里面的图标都是使用的image组件,看起来非常别扭,加载也不太顺畅. 就想着看看微信有没有类似自带的图标库可以使用. 有是有,就是太少了,翻来翻去好像也就 8 种, ...

  8. 微信小程序-WXSS

    WXSS(WeiXin Style Sheets)是一套样式语言,用于描述 WXML 的组件样式. WXSS 用来决定 WXML 的组件应该怎么显示. 为了适应广大的前端开发者,我们的 WXSS 具有 ...

  9. less文件编译成微信小程序wxss文件

    2016年9月21日,微信小程序正式开启内测.在微信生态下,触手可及.用完即走的微信小程序引起广泛关注,刷爆朋友圈子.在这样的火爆氛围中,作为一个前端开发者的我,也悄悄地去尝鲜.在做demo小示例的过 ...

随机推荐

  1. 跳转控制语句continue

    1 continue的使用场景: 1.1 在循环语句中 注意:离开使用场景的存在是没有意义的 2 continue的作用: 2.1 单层循环对比break,然后总结两者的区别 2.1.1 break ...

  2. luogu P1068 分数线划定 x

    P1068 分数线划定 题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A 市对 所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试.面试分数线根 据 ...

  3. RedisTemplate访问Redis数据结构(四)——Set

    Redis的Set是string类型的无序集合.集合成员是唯一的,这就意味着集合中不能出现重复的数据,Redis 中 集合是通过哈希表实现的,所以添加,删除,查找的复杂度都是O(1). SetOper ...

  4. [CF1082G]Petya and Graph:最小割

    分析 发这篇博客的目的就是要让你们知道博主到底有多菜. 类似于[NOI2006]最大获利.(明明就是一模一样好吧!) 不知道怎么了,半秒就想到用网络流,却没想出怎么建图. 连这么简单的题都没做出来,我 ...

  5. [BZOJ2225][SPOJ2371]LIS2 - Another Longest Increasing Subsequence Problem:CDQ分治+树状数组+DP

    分析 这回试了一下三级标题,不知道效果怎么样? 回到正题,二维最长上升子序列......嗯,我会树套树. 考虑\(CDQ\)分治,算法流程: 先递归进入左子区间. 将左,右子区间按\(x\)排序. 归 ...

  6. Swift equality

    最后更新: 2017-07-23 在程序开发中,我们时常需要来判断两个对象是否相等.在编程思想中,两个对象相等指的是在内存中的地址相同,也就是两个指针指向同一个地址.但是在日常理解中,只要两个对象的内 ...

  7. [CSP-S模拟测试]:模板(ac)(线段树启发式合并)

    题目描述 辣鸡$ljh\ NOI$之后就退役了,然后就滚去学文化课了.他每天都被$katarina$大神虐,仗着自己学过一些姿势就给$katarina$大神出了一道题.有一棵$n$个节点的以$1$号节 ...

  8. 关于c++ error : passing " "as" " discards qualifiers

    http://www.cppblog.com/cppblogs/archive/2012/09/06/189749.html 今天写了一段小代码,本以为正确,但运行后,就somehow ”discar ...

  9. idea中svn代码冲突

    1.鼠标右键点击项目根目录 --> 2.选择 subversion --> 3.resolve Text Confict --> 4.merge 手动编辑冲突部分,解决后就能正常提交 ...

  10. SourceTree跳过初始设置

    转载https://www.cnblogs.com/xiofee/p/sourcetree_pass_initialization_setup.html 如何跳过初始设置,只需要在安装路径中添加一个a ...