-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (40 loc) · 1.47 KB
/
Copy pathscript.js
File metadata and controls
49 lines (40 loc) · 1.47 KB
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
const countdownDate = new Date('2050-05-20T12:00:00+07:00').getTime();
const daysEl = document.getElementById('days');
const hoursEl = document.getElementById('hours');
const minutesEl = document.getElementById('minutes');
const secondsEl = document.getElementById('seconds');
function updateCountdown() {
if (!daysEl || !hoursEl || !minutesEl || !secondsEl) return;
const now = Date.now();
const distance = countdownDate - now;
if (distance <= 0) {
daysEl.textContent = hoursEl.textContent = minutesEl.textContent = secondsEl.textContent = '0';
return;
}
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
daysEl.textContent = days;
hoursEl.textContent = hours;
minutesEl.textContent = minutes;
secondsEl.textContent = seconds;
}
setInterval(updateCountdown, 1000);
updateCountdown();
const audioBtn = document.querySelector('[data-audio-btn]');
const audio = document.getElementById('bg-audio');
audioBtn?.addEventListener('click', async () => {
if (!audio) return;
try {
if (audio.paused) {
await audio.play();
audioBtn.classList.add('is-playing');
} else {
audio.pause();
audioBtn.classList.remove('is-playing');
}
} catch (error) {
console.warn('Không thể phát nhạc:', error);
}
});