-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
241 lines (194 loc) · 8.65 KB
/
index.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#FF0000"> <!-- Sesuaikan warna tema -->
<link rel="icon" type="image/png" href="./winner-logo.svg"> <!-- Ganti dengan favicon sesuai kebutuhan -->
<title>Lucky Draw</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="./fontawesome-free-6.5.1-web/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.2/dist/confetti.browser.min.js"></script>
<style>
@keyframes highlightWinner {
0% {
transform: scale(1);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
@keyframes scrollAnimation {
from {
transform: translateY(0);
}
to {
transform: translateY(-100%);
}
}
.scrolling-names {
animation: scrollAnimation 5s linear infinite;
/* Sesuaikan durasi animasi yang diinginkan */
display: inline-block;
}
</style>
</head>
<body class="flex items-center justify-center bg-red-500 h-screen">
<div class="bg-gray-100 p-8 rounded-md shadow-md sm:w-96 md:w-1/2 lg:w-1/3 xl:w-1/4 text-center">
<h1 class="text-2xl font-bold mb-4">Lucky Draw</h1>
<div id="winner" class="mb-4"></div>
<!-- Tambahkan elemen audio untuk suara -->
<audio id="winnerSound" src="./winner-sound.mp3"></audio>
<audio id="drawingSound" src="./draw-sound.mp3"></audio>
<button onclick="toggleDraw()" id="drawButton" class="bg-yellow-400 text-gray-100 px-4 py-2 rounded-md">Draw
Winner</button>
<!-- Tombol Setting -->
<button onclick="toggleSettings()" class="absolute top-0 right-0 m-2 p-2 bg-red-300 rounded-md"><i
class="fas fa-gear"></i></button>
<!-- Tombol Fullscreen -->
<button onclick="toggleFullscreen()" id="fullscreenButton"
class="absolute top-0 right-0 md:right-10 m-2 p-2 bg-red-300 rounded-md">
<i class="fas fa-expand"></i>
</button>
<!-- Menu Input Nama Peserta -->
<div id="settingsMenu"
class="hidden absolute top-0 right-0 mt-10 p-4 bg-white border border-gray-300 rounded-md">
<h2 class="text-lg font-bold mb-2">Input Participants</h2>
<textarea id="participantInput" class="w-full h-20 border border-gray-300 p-2 mb-2"
placeholder="Enter participant names (one per line)"></textarea>
<button onclick="saveParticipants()" class="bg-green-500 text-white px-4 py-2 rounded-md mr-2">Save</button>
<button onclick="discardParticipants()" class="bg-red-500 text-white px-4 py-2 rounded-md">Discard</button>
</div>
</div>
<script>
let participants = [];
let isDrawing = false;
let drawInterval;
function toggleDraw() {
const drawButton = document.getElementById('drawButton');
const winnerContainer = document.getElementById('winner');
const drawingSound = document.getElementById('drawingSound');
const winnerSound = document.getElementById('winnerSound');
// Jika tidak ada nama peserta, buka menu setting
if (participants.length === 0) {
toggleSettings();
return;
}
if (!isDrawing) {
drawButton.textContent = 'Stop';
isDrawing = true;
// Mulai suara selama pengundian
drawingSound.play();
// Set properti loop agar suara berulang
drawingSound.loop = true;
drawInterval = setInterval(() => {
animateRandomName(winnerContainer);
}, 30);
} else {
drawButton.textContent = 'Draw Winner';
isDrawing = false;
clearInterval(drawInterval);
// Hentikan suara selama pengundian
drawingSound.pause();
drawingSound.currentTime = 0;
// Hentikan looping suara
drawingSound.loop = false;
// Memutar suara ketika nama pemenang muncul
winnerSound.play();
const winnerIndex = Math.floor(Math.random() * participants.length);
const winner = participants[winnerIndex];
// Tambahkan kelas animasi pada nama pemenang
winnerContainer.innerHTML = `<p class="text-green-500 font-bold animate-pulse">Winner: ${winner}</p>`;
participants.splice(winnerIndex, 1);
// Menambahkan efek confetti
startConfetti();
}
}
function startConfetti() {
// Konfigurasi efek confetti
var end = Date.now() + (15 * 1000);
var schoolPrideColors = ['#ff0000', '#ffffff'];
(function frame() {
confetti({
particleCount: 2,
angle: 60,
spread: 55,
origin: { x: 0 },
colors: schoolPrideColors
});
confetti({
particleCount: 2,
angle: 120,
spread: 55,
origin: { x: 1 },
colors: schoolPrideColors
});
if (Date.now() < end) {
requestAnimationFrame(frame);
}
}());
// Memanggil fungsi confetti dari library
confetti(confettiConfig);
}
function toggleSettings() {
const settingsMenu = document.getElementById('settingsMenu');
settingsMenu.classList.toggle('hidden');
}
function saveParticipants() {
const participantInput = document.getElementById('participantInput');
const newParticipants = participantInput.value.split('\n').map(name => name.trim()).filter(name => name !== '');
participants = [...participants, ...newParticipants];
// Menutup menu setting
toggleSettings();
}
function discardParticipants() {
document.getElementById('participantInput').value = '';
// Menutup menu setting
toggleSettings();
}
function animateRandomName(container) {
const randomName = participants[Math.floor(Math.random() * participants.length)];
const scrollingNameElement = document.createElement('p');
scrollingNameElement.className = 'text-blue-500 font-bold scrolling-names';
scrollingNameElement.textContent = `Drawing: ${randomName}`;
// Bersihkan kontainer sebelum menambahkan elemen baru
container.innerHTML = '';
container.appendChild(scrollingNameElement);
}
function toggleFullscreen() {
const fullscreenButton = document.getElementById('fullscreenButton');
const element = document.documentElement;
if (!document.fullscreenElement) {
// Masuk ke mode fullscreen
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
// Mengubah ikon tombol menjadi "Exit Fullscreen"
fullscreenButton.innerHTML = '<i class="fas fa-compress"></i>';
} else {
// Keluar dari mode fullscreen
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
// Mengubah ikon tombol menjadi "Fullscreen"
fullscreenButton.innerHTML = '<i class="fas fa-expand"></i>';
}
}
</script>
</body>
</html>