简体   繁体   English

如何静音/取消静音 JavaScript 中的某些文件的所有声音?

[英]How can I mute/unmute all sounds of some files in JavaScript?

I'am creating a game that have some storage sounds host in JavaScripts files, like this:我正在创建一个游戏,它在 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");

Can I create a button in my index.html to when click, he switch to mute/unmute the sound of this files... Is that possible?我可以在我的index.html中创建一个按钮,当点击时,他切换到静音/取消静音这个文件的声音......这可能吗? How?如何?

My project contain 5 files in JavaScript, i want to mute all of then我的项目在 JavaScript 中包含 5 个文件,我想将所有文件静音

You can do it this way.你可以这样做。 The click function will stop the music when it happens点击 function 会停止音乐

 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() }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM