Answers for "play background music in jasvascript"

0

play background music in html jasvascript

<audio src="https://www.bensound.com/bensound-music/bensound-moose.mp3"></audio>

<Script>
  window.addEventListener("DOMContentLoaded", event => {
    const audio = document.querySelector("audio");
    audio.volume = 0.2;
    audio.play();
  });
</Script>
Posted by: Guest on June-02-2021
0

play background music in jasvascript

const button = document.querySelector("#button");
const icon = document.querySelector("#button > i");
const audio = document.querySelector("audio");

button.addEventListener("click", () => {
  if (audio.paused) {
    audio.volume = 0.2;
    audio.play();
    icon.classList.remove('fa-volume-up');
    icon.classList.add('fa-volume-mute');
    
  } else {
    audio.pause();
    icon.classList.remove('fa-volume-mute');
    icon.classList.add('fa-volume-up');
  }
  button.classList.add("fade");
});
Posted by: Guest on June-02-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language