-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (31 loc) · 1009 Bytes
/
Copy pathscript.js
File metadata and controls
41 lines (31 loc) · 1009 Bytes
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
const audio = document.getElementById("bg-music");
const btn = document.getElementById("music-toggle1");
const footerToggle = document.getElementById("music-toggle2");
audio.volume = 0.3;
let isPlaying = false;
/* ================= NAVBAR BUTTON ================= */
btn.onclick = () => {
if (audio.paused) {
audio.play();
btn.textContent = "🔊";
isPlaying = true;
} else {
audio.pause();
btn.textContent = "🔇";
isPlaying = false;
}
};
/* ================= FOOTER CLICK (same functionality, no text change) ================= */
footerToggle.onclick = () => {
if (audio.paused) {
audio.play();
btn.textContent = "🔊"; // sync navbar button
} else {
audio.pause();
btn.textContent = "🔇"; // sync navbar button
}
};
/* ================= ON REFRESHING, FORCE SCROLL TO TOP ================= */
window.onload = () => {
window.scrollTo(0, 0);
};