-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlottery.html
161 lines (147 loc) · 5.18 KB
/
lottery.html
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://at.alicdn.com/t/c/font_4716565_ln0phq5wyx.css">
<title>lottery</title>
<style>
.lottery {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #02000086;
overflow: hidden;
}
.lo-container {
position: relative;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.lo-container .lo-card {
position: absolute;
width: 240px;
height: 360px;
background-color: #5e5cfc;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
color: rgba(0, 0, 0, 0);
font-size: 8em;
font-weight: 800;
border: 10px solid rgba(0, 0, 0, .1);
transform-origin: 50% 100%;
transition: .5s;
filter: hue-rotate(calc(var(--i)*60deg));
box-shadow: 0 10px 10px rgba(0, 0, 0, .1);
cursor: pointer;
}
.lo-container:hover .lo-card {
transform: rotate(calc(var(--i)*5deg)) translate(calc(var(--i)*120px), -50px);
color: rgba(0, 0, 0, .5);
box-shadow: 0 10px 10px rgba(0, 0, 0, .25);
}
.lo-container .lo-card:hover {
translate: calc(var(--i)*20px) -50px;
}
.active {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/* 中心对齐 */
background-color: rgb(210, 217, 198);
color: black;
z-index: 10;
/* 提升到最上层 */
}
.lo-container .lo-card.hidden {
display: none;
}
.selected-card {
position: absolute;
width: 240px;
height: 360px;
background-color: #5e5cfc;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
color: rgba(0, 0, 0, 0.5);
font-size: 8em;
font-weight: 800;
border: 10px solid rgba(0, 0, 0, .1);
transform-origin: 50% 100%;
transition: .5s;
filter: hue-rotate(calc(var(--i)*60deg));
box-shadow: 0 10px 10px rgba(0, 0, 0, .1);
cursor: pointer;
}
#resetButton {
position: absolute;
border-radius: 50%;
width: 100px;
height: 100px;
right: 20px;
bottom: 50px;
}
</style>
</head>
<body>
<div class="lottery">
<div class="lo-container">
<div class="lo-card" style="--i:-4;">1</div>
<div class="lo-card" style="--i:-3;">2</div>
<div class="lo-card" style="--i:-2;">3</div>
<div class="lo-card" style="--i:-1;">4</div>
<div class="lo-card" style="--i:0;">5</div>
<div class="lo-card" style="--i:1;">6</div>
<div class="lo-card" style="--i:2;">7</div>
<div class="lo-card" style="--i:3;">8</div>
<div class="lo-card" style="--i:4;">9</div>
</div>
<!-- <button id="resetButton" onclick="resetButton()">
<div class="reset-icon" style="scale:3;">
<i class="iconfont icon-reload" style="scale: 1.5;"></i>
</div>
</button> -->
</div>
<script>
const cards = document.querySelectorAll('.lo-card');
cards.forEach(function (card) {
card.addEventListener('click', function () {
// 获取点击的卡片索引
const clickedIndex = Array.from(cards).indexOf(card);
// 固定其他卡片的位置
cards.forEach((c, index) => {
if (index !== clickedIndex) {
const rect = c.getBoundingClientRect();
c.classList.add('cardhidden'); // 添加隐藏
}
});
// 将被点击的卡片移动到屏幕中心并翻转
card.textContent = Math.floor(Math.random() * 100) + 1; // 生成随机数
card.classList.remove('lo-card')
card.classList.add('selected-card')
card.classList.add('cardactive'); // 使其成为活动卡片
});
});
function resetButton() {
var cards = document.querySelectorAll('.lo-card')
var selectedCard = document.getElementsByClassName('selected-card')[0]
cards.forEach(function (card) {
card.classList.remove('cardhidden')
})
if (selectedCard) {
selectedCard.classList.add('lo-card')
selectedCard.classList.remove('selected-card')
selectedCard.classList.remove('cardactive')
}
}
</script>
</body>
</html>