-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic.js
35 lines (32 loc) · 1.12 KB
/
dynamic.js
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
var buttonContainer = document.getElementById("button-positioning");
var buttons = document.getElementsByClassName("buttons");
var audio = new Audio();
var timePassed = 200;
audio.src = `The_Aluminium_Tough_-_Round_The_Twist.mp3`;
audio.currentTime = timePassed;
const buttonClicked = () => {
if (buttons[0].style.display === "block") {
audio.play();
buttons[0].style.display = "none";
buttons[1].style.display = "block";
} else if (buttons[1].style.display === "block") {
audio.pause();
buttons[1].style.display = "none";
buttons[0].style.display = "block";
}
// else if (buttons[2].style.display === "block") {
// audio.currentTime = 0;
// audio.play();
// buttons[2].style.display = "none";
// buttons[1].style.display = "block";
// }
};
buttonContainer.addEventListener("click", buttonClicked);
const musicEnded = () => {
buttons[0].style.display = "none";
buttons[1].style.display = "block";
//buttons[2].style.display = "block";
audio.currentTime = 0;
audio.play();
};
audio.addEventListener("ended", musicEnded);