1<audio src="https://www.bensound.com/bensound-music/bensound-moose.mp3"></audio>
2
3<Script>
4 window.addEventListener("DOMContentLoaded", event => {
5 const audio = document.querySelector("audio");
6 audio.volume = 0.2;
7 audio.play();
8 });
9</Script>
1const button = document.querySelector("#button");
2const icon = document.querySelector("#button > i");
3const audio = document.querySelector("audio");
4
5button.addEventListener("click", () => {
6 if (audio.paused) {
7 audio.volume = 0.2;
8 audio.play();
9 icon.classList.remove('fa-volume-up');
10 icon.classList.add('fa-volume-mute');
11
12 } else {
13 audio.pause();
14 icon.classList.remove('fa-volume-mute');
15 icon.classList.add('fa-volume-up');
16 }
17 button.classList.add("fade");
18});
19
20