# 抽奖轮盘

预览效果 (opens new window)

  1. html部分
<div class="container">
  <div class="spinBtn">spin</div>
  <div class="wheel">
    <div class="mumber" style="--i: 1; --clr: #db7093">
      <span>100</span>
    </div>
    <div class="mumber" style="--i: 2; --clr: #20b2aa">
      <span>1</span>
    </div>
    <div class="mumber" style="--i: 3; --clr: #d63e92">
      <span>50</span>
    </div>
    <div class="mumber" style="--i: 4; --clr: #daa520">
      <span>20</span>
    </div>
    <div class="mumber" style="--i: 5; --clr: #ff340f">
      <span>80</span>
    </div>
    <div class="mumber" style="--i: 6; --clr: #ff7f50">
      <span>200</span>
    </div>
    <div class="mumber" style="--i: 7; --clr: #3cb371">
      <span>120</span>
    </div>
    <div class="mumber" style="--i: 8; --clr: #416028">
      <span>90</span>
    </div>
  </div>
</div>
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
  1. css部分
@import url("https://fonts.googleapis.com/css?family=Poppins:200,300,400,500,600,700,800,900&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins" sans-serif;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #333;
}
.container {
  position: relative;
  width: 400px;
  height: 400px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container .spinBtn {
  position: absolute;
  width: 60px;
  height: 60px;
  background: #fff;
  border-radius: 50%;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
  font-weight: 600;
  color: #333;
  letter-spacing: 0.1em;
  cursor: pointer;
  user-select: none;
}
.container .spinBtn::before {
  content: "";
  position: absolute;
  top: -28px;
  width: 20px;
  height: 30px;
  background: #fff;
  clip-path: polygon(50% 0%, 15% 100%, 85% 100%);
}
.container .wheel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #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;
}
.container .wheel .mumber {
  position: absolute;
  width: 50%;
  height: 50%;
  background: var(--clr);
  transform-origin: bottom right;
  transform: rotate(calc(45deg * var(--i)));
  clip-path: polygon(0 0, 55% 0, 100% 100%, 0 55%);
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
}
.container .wheel .mumber 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);
}
.container .wheel .mumber span::after {
  content: "$";
  position: absolute;
  font-size: 0.75em;
  font-weight: 500;
}

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
  1. js部分
const query = (dom) => document.querySelector(dom);

const startRotate = () => Math.ceil(Math.random() * 3600);

let wheel = query(".wheel");
let spinBtn = query(".spinBtn");
let rotateDeg = startRotate();

spinBtn.onclick = function () {
  // console.log("click");
  wheel.style.transform = "rotate(" + rotateDeg + "deg)";
  rotateDeg = startRotate();
};

1
2
3
4
5
6
7
8
9
10
11
12
13
14
最后更新时间: 5/15/2023, 6:25:18 PM