-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled-2.js
More file actions
40 lines (34 loc) · 1.29 KB
/
Untitled-2.js
File metadata and controls
40 lines (34 loc) · 1.29 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
const audio = document.getElementById("audio-player");
let currentWave;
// Handle play/pause buttons on each track
document.querySelectorAll(".play-btn").forEach(btn => {
btn.addEventListener("click", () => {
const audioSrc = btn.getAttribute("data-audio");
const wave = btn.nextElementSibling;
// Reset all other tracks
document.querySelectorAll(".wave").forEach(w => w.style.display = "none");
document.querySelectorAll(".play-btn").forEach(b => b.textContent = "▶");
// If same track playing, pause it
if (!audio.paused && audio.src.includes(audioSrc)) {
audio.pause();
btn.textContent = "▶";
wave.style.display = "none";
return;
}
// Play selected track
audio.src = audioSrc;
audio.play();
btn.textContent = "⏸";
wave.style.display = "block";
currentWave = wave;
});
});
// When audio ends, reset buttons
audio.addEventListener("ended", () => {
document.querySelectorAll(".play-btn").forEach(b => b.textContent = "▶");
if (currentWave) currentWave.style.display = "none";
});
// Smooth scroll to trending tracks when CTA clicked
document.querySelector(".cta").addEventListener("click", () => {
document.querySelector(".tracks").scrollIntoView({ behavior: "smooth" });
});