首页 > 编程语言 >css 转盘抽奖(兼容微信小程序)

css 转盘抽奖(兼容微信小程序)

时间:2024-01-29 17:00:28浏览次数:29  
标签:winningIndex rotate console log 微信 else css 转盘 deg


<template>
  <div class="turntable" v-wechat-title="$route.meta.title">
    <!-- 转盘包裹 -->
    <div class="rotate">
      <!-- 转盘图片 -->
      <image class="dish" src="../../static/secondYear/dial.png" :style="{ width: w, height: h, transform: rotate_deg, transition: rotate_transition }" />
      <!-- 指针图片 -->
      <image class="pointer" src="../../static/secondYear/click.png" @click="start" :style="{ width: clickW, height: clickH }"/>
    </div>
    <div class="times">剩余抽奖次数 {{ LuckyClick }}</div>
  </div>
</template>

<script>
export default {
  name: "turntable",
  data() {
    return {
      LuckyClick: 3,
      circleList: [], //原点设置
      colorCircleFirst: "#FE4D32", //圆点颜色
      colorCircleSecond: "#fff", //圆点颜色

      cat: 45, //总共8个扇形区域,每个区域约45度
      isAllowClick: true, //是否能够点击
      rotate_deg: 0, //指针旋转的角度
      rotate_transition: "transform 3s ease-in-out", //初始化选中的过度属性控制
      w: "710rpx", // 转盘图片的宽
      h: "710rpx",  // 转盘图片的高
      clickW: '162rpx',
      clickH: '162rpx',
      winningIndex: 0, // 获奖的index
      lastDeg: 0, // 最后一次旋转的度数
      isFistClick: true, // 是否是第一次点击
    };
  },

  components: {
    // Calendar: Calendar
  },
  created() {
    // this.showcircleList();
  },

  watch: {},

  mounted() { },

  methods: {
    start() {
      if (this.LuckyClick == 0) {
        return uni.showToast({
          title: "您的抽奖次数已使用完毕,请稍后再试",
          icon: "none",
          duration: 2000
        });
      } else {
        this.rotating();
      }
    },

    rotating() {
      const that = this
      if (!this.isAllowClick) return;
      this.isAllowClick = false;
      this.rotate_transition = "transform 3s ease-in-out";
      this.LuckyClick--;
      var rand_circle = 5; //默认多旋转5圈
      // this.winningIndex = this.getAward(); //设置了概率的
      this.winningIndex = 8;

      console.log(this.winningIndex);
      const randomDeg = this.winningIndex * 45 - 20; //当前下标对应的角度    45是总共8个扇形区域,每个区域约45度
        let deg = 0
        if(this.isFistClick) {
          deg = rand_circle * 360 + randomDeg
        } else {
          deg = rand_circle * 360 + randomDeg + this.lastDeg
        }
        console.log(this.isFistClick, deg, '22222')
        this.rotate_deg = "rotate(" + deg + "deg)"
        this.isFistClick = false
        this.lastDeg = deg + Math.abs(360 - randomDeg)

      setTimeout(function () {
        that.isAllowClick = true;
        that.rotate_transition = "";

        if (this.winningIndex == 0) {
          console.log("恭喜您,IphoneX");
        } else if (this.winningIndex == 1) {
          console.log("恭喜您,获得10元现金");
        } else if (this.winningIndex == 2) {
          console.log("很遗憾,重在参与");
        } else if (this.winningIndex == 3) {
          console.log("恭喜您,获得30元现金");
        } else if (this.winningIndex == 4) {
          console.log("恭喜您,获得20元现金");
        } else if (this.winningIndex == 5) {
          console.log("恭喜您,获得50元现金");
        } else if (this.winningIndex == 6) {
          console.log("恭喜您,获得5元现金");
        } else if (this.winningIndex == 7) {
          console.log("恭喜您,获得100元现金");
        }
      }, 2000);
    },

    //设置概率
    getAward() {
      const winIndex = 2;
      return winIndex;
    }
  },

};
</script>

<style  scoped lang="scss">
.turntable {
  .rotate {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .pointer {
      position: absolute;
      top: 44%;
      left: 49%;
      transform: translate(-45%, -50%);
    }
  }
  .times {
    font-size: 26rpx;
    color: #FFE3B4;
    position: absolute;
    bottom: 7rpx;
    left: 50%;
    transform: translateX(-50%);
  }
}

</style>

标签:winningIndex,rotate,console,log,微信,else,css,转盘,deg
From: https://www.cnblogs.com/DL-CODER/p/17994890

相关文章

  • css实现子元素整体居中,最后一行靠左。grid布局
    <divclass="container"><divclass="item">1</div><divclass="item">2</div><divclass="item">3</div><divclass="item">4</div><divclass......
  • 微信小程序:弹框
    一、自定义弹框组件1、组件定义在components目录下创建dialog文件夹,然后选择文件夹,右键,点击"新建Component",就会创建四个文件。如下所示:wxml<!--components/dialog/index.wxml--><viewwx:if="{{isShow}}"class="tip-area"><viewbindtap="hideClick"c......
  • 局域网电脑自动监控软件,微信泄密|QQ泄密|邮件泄密通通一网打尽
    本文一共:1035字|预计阅读时间:5分钟局域网电脑自动监控软件1.功能概述在当前信息时代,随着电脑网络的广泛应用,网络安全问题日益突出。为了有效应对各种潜在的泄密风险,域智盾软件推出了一款强大的局域网电脑自动监控软件。该软件具备微信、QQ、企业微信、钉钉、邮件等多方面监......
  • 微信小程序:生成二维码
    wxml<view><buttonbindtap='createQrcode'type="primary"style="width:400rpx;margin-top:400rpx;">生成二维码</button><canvasid='qrcode'type="2d"style='width:300rpx;height:30......
  • 苹果支付有哪些坑,为什么苹果支付比支付宝和微信容易丢单?
    苹果内购前言苹果内购苹果支付的难点方案设计1、商品设计2、用户和回执的绑定3、回调的重试充值冲遇到的问题点1、丢单2、充值成功,下发的物品不对3、处理退款苹果订阅1、配置服务端回调通知2、客户端通知;3、服务端定时轮询;StoreKit1对比2新的api......
  • 2024最新苹果iOS17.3微信分身详解分享
    微信是目前最流行的社交软件之一,拥有庞大的用户群体。然而,对于一些需要同时使用多个微信账号的用户来说,使用官方版微信就显得有些不方便。iOS分身微信软件可以解决这个问题,它可以让用户在同一台设备上同时登录多个微信账号,从而实现工作生活两不误。iOS分身微信软件的优势iOS......
  • css背景图片实现object-fit的效果
     object-fit是一个用于控制替换元素(如<img>或<video>)内容在其容器内布局和缩放的CSS属性。它的作用是调整替换元素的尺寸和位置,使其适应容器,并保持其纵横比例。然而,object-fit属性本身并不直接适用于背景图片。如果你想在背景图片上应用object-fit效果,可以使用background-size......
  • css其他
    1、   css水平、垂直居中水平居中1)行内元素:text-align:center2)块级元素:margin:0auto3)position:absolute+left:50%+transform:translateX(-50%)4)display:flexjustify-content:center垂直居中1)设置line-height等于he......
  • 头像和消息组件css实现思路
    修改后:实现代码(可以用于组装头像和消息):<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>D......
  • 微信小程序中使用Vant Weapp组件库
    【快速上手-VantWeapp(gitee.io)】【node版本对应的npm版本表-菜小鱼~-博客园(cnblogs.com)】【报错npmERR!Acompletelogofthisruncanbefoundin:npmERR!-CSDN博客】【解决:npminstall报错‘Theoperationwasrejectedbyyouroperatingsystem‘-C......