当前位置:   article > 正文

微信小程序---抽奖_抽奖小程序代码

抽奖小程序代码

开发项目提出抽奖功能,因自己没有写过,所以问了度娘,这个直接复制粘贴,然后就能实现抽奖功能,其他的样式,图片可根据自己项目需求进行添加

wxml:

  1. <view class="index">
  2. <view class="xian"></view>
  3. <view class="xian"></view>
  4. <view class="xian"></view>
  5. <view class="detail">一等奖</view>
  6. <view class="detail">二等奖</view>
  7. <view class="detail">三等奖</view>
  8. <view class="detail">四等奖</view>
  9. <view class="detail">五等奖</view>
  10. <view class="detail">六等奖</view>
  11. <span bindtap="zhuanin" style="transform:rotate({{trasn}}deg);"></span>
  12. </view>

 wxss:

  1. .index{
  2. width: 300px;
  3. margin: 50rpx calc((100% - 300px) / 2);
  4. border:1px solid #ffcccc;
  5. border-radius: 50%;
  6. height: 300px;
  7. position: relative;
  8. overflow: hidden;
  9. font-size: 26rpx;
  10. }
  11. .xian{
  12. width:300px;
  13. height:1px;
  14. background:#d6d6d6;
  15. position:absolute;
  16. top:150px;
  17. left:0;
  18. }
  19. .index>.xian:nth-child(2){
  20. transform:rotateZ(60deg)
  21. }
  22. .index>.xian:nth-child(3){
  23. transform:rotateZ(120deg)
  24. }
  25. .detail{
  26. position: absolute;
  27. }
  28. .index>.detail:nth-child(4){
  29. top:25px;left:132px;
  30. }
  31. .index>.detail:nth-child(5){
  32. top:90px;left:225px;
  33. }
  34. .index>.detail:nth-child(6){
  35. top:190px;left:225px;
  36. }
  37. .index>.detail:nth-child(7){
  38. top:250px;left:132px;
  39. }
  40. .index>.detail:nth-child(8){
  41. top:190px;left:40px;
  42. }
  43. .index>.detail:nth-child(9){
  44. top:90px;left:40px;
  45. }
  46. .index>span{
  47. width: 30px;
  48. height: 30px;
  49. background-color: #ffcccc;
  50. border-radius: 50%;
  51. position: absolute;
  52. left: 135px;
  53. top:135px;
  54. }
  55. .index>span::after{
  56. content: ' ';
  57. width:0;
  58. height:0;
  59. border-right:6px solid transparent;
  60. border-left:6px solid transparent;
  61. border-bottom:26px solid #ffcccc;
  62. z-index: 10;
  63. position: absolute;
  64. left: 8.5px;
  65. top: -24px;
  66. }

js:

  1. Page({
  2. data: {
  3. random:'',
  4. trasn:0,
  5. },
  6. zhuanin:function(e){
  7. let that = this
  8. let num = 0
  9. that.setData({
  10. random:Math.floor(Math.random() * 360),
  11. trasn:0,
  12. })
  13. let a = setInterval(function () {
  14. that.setData({
  15. trasn:that.data.trasn+5
  16. })
  17. if(360 <= that.data.trasn){
  18. that.data.trasn = 0
  19. num = num + 1
  20. }
  21. if(num == 3){
  22. that.currinl()
  23. clearInterval(a)
  24. }
  25. },5)
  26. },
  27. currinl:function(e){
  28. let that = this
  29. let name = ''
  30. if(that.data.random == 30 || that.data.random == 90 || that.data.random == 150 || that.data.random == 210 || that.data.random == 330){
  31. that.setData({
  32. random:that.data.random + 1
  33. })
  34. }
  35. if(that.data.random < 30 || 330 < that.data.random){
  36. name = '一等奖'
  37. }else if(that.data.random > 30 && that.data.random < 90){
  38. name = '二等奖'
  39. }else if(that.data.random > 90 && that.data.random < 150){
  40. name = '三等奖'
  41. }else if(that.data.random > 150 && that.data.random < 210){
  42. name = '四等奖'
  43. }else if(that.data.random > 210 && that.data.random < 270){
  44. name = "五等奖"
  45. }else{
  46. name = "六等奖"
  47. }
  48. let b = setInterval(function () {
  49. that.setData({
  50. trasn:that.data.trasn+2
  51. })
  52. if(that.data.random <= that.data.trasn){
  53. wx.showToast({
  54. title: name,
  55. icon: 'none',
  56. duration: 2000
  57. })
  58. clearInterval(b)
  59. }
  60. },10)
  61. },
  62. })

微信开发者工具直接cv大法就可以实现

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/198914
推荐阅读
相关标签
  

闽ICP备14008679号