SpinningWheelGame.vue 3.01 KB
Newer Older
hucy's avatar
hucy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
<!--
 * 转轮游戏
-->
<script setup lang="ts">
import { ref } from 'vue';

const wheelRef = ref<any>(null);
const val = ref(Math.ceil(Math.random() * 3600));

function spinClick() {
  wheelRef.value.style.transform = `rotate(${val.value}deg)`;
  val.value += Math.ceil(Math.random() * 3600);
}
</script>
<template>
  <div class="box fit">
    <div class="container">
      <div class="spin-btn" @click="spinClick">开始</div>
      <div class="wheel" ref="wheelRef">
        <div class="number" style="--i: 1; --clr: #f2bdd0">
          <span>100</span>
        </div>
        <div class="number" style="--i: 2; --clr: #f0f4c1"><span>1</span></div>
        <div class="number" style="--i: 3; --clr: #cccc99"><span>50</span></div>
        <div class="number" style="--i: 4; --clr: #cccccc"><span>0</span></div>
        <div class="number" style="--i: 5; --clr: #cb7575">
          <span>1000</span>
        </div>
        <div class="number" style="--i: 6; --clr: #ecb83c"><span>10</span></div>
        <div class="number" style="--i: 7; --clr: #d3e397"><span>5</span></div>
        <div class="number" style="--i: 8; --clr: #f8dcdc"><span>20</span></div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #333;
}
.container {
  position: relative;
  width: 400px;
  height: 400px;
  display: flex;
  justify-content: center;
  align-items: center;

  .spin-btn {
    position: absolute;
    width: 60px;
    height: 60px;
    background-color: #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    color: #333;
    letter-spacing: 0.1em;
    border: 4px solid rgba(0, 0, 0, 0.75);
    cursor: pointer;
    user-select: none;
    z-index: 10;

    &::before {
      content: '';
      position: absolute;
      width: 20px;
      height: 30px;
      background-color: #fff;
      top: -28px;
      clip-path: polygon(50% 0%, 15% 100%, 85% 100%);
    }
  }

  .wheel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #333;
    border-radius: 50%;
    box-shadow: 0 0 0 5px #333, 0 0 0 15px #fff, 0 0 0 18px #111;
    transition: transform 5s ease-in-out;

    .number {
      position: absolute;
      width: 50%;
      height: 50%;
      background-color: var(--clr);
      transform-origin: bottom right;
      transform: rotate(calc(45deg * var(--i)));
      clip-path: polygon(0 0, 56% 0, 100% 100%, 0 56%);
      display: flex;
      justify-content: center;
      align-items: center;
      user-select: none;
      span {
        position: relative;
        transform: rotate(45deg);
        font-size: 2em;
        font-weight: 700;
        color: #fff;
        text-shadow: 3px 5px 2px rgba(0, 0, 0, 0.15);
        &::after {
          content: '¥';
          position: absolute;
          top: 5px;
          font-size: 0.75em;
          font-weight: 500;
        }
      }
    }
  }
}
</style>