我正在创建一个在JavaScripts文件中托管一些存储声音的游戏,比如:
let gameOver = false;
let gameWin = false;
const gameOverSound = new Audio("sounds/fim.wav");
const gameOverSound = new Audio("sounds/fim.wav");
const gameWinSound = new Audio("sounds/gameWin.wav");
我可以在index.html中创建一个按钮吗?当点击时,他会切换到静音/取消静音这个文件的声音有可能吗?如何
我的项目包含5个JavaScript文件,我想将所有文件静音
您可以这样做。点击功能将在发生时停止音乐
let gameOver = false;
let gameWin = false;
const gameOverSound = new Audio("sounds/fim.wav");
const gameOverSound = new Audio("sounds/fim.wav");
const gameWinSound = new Audio("sounds/gameWin.wav");
let stopButton = document.querySelector("DivClass or DivID");
stopButton.onclik = ()=>{
gameOverSound.pause()
gameWinSound.pause()
}