play background music in html jasvascript

Solutions on MaxInterview for play background music in html jasvascript by the best coders in the world

showing results for - "play background music in html jasvascript"
Jannik
21 Apr 2016
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>
Debora
19 Mar 2019
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