2

我已经了解了如何<audio>通过输入以下代码来使声音对象静音:

<a href="#" onclick="document.getElementById('ambiance').muted = true; return false">
    mute sound
</a>

现在我正在搜索如何使用带有切换选项的相同按钮来静音/取消静音我的声音?

谁能给我指路?

4

2 回答 2

9
var audioElm = document.getElementById('ambiance'); audioElm.muted = !audioElm.muted;
于 2011-10-17T19:32:31.707 回答
0

尝试这个:

.unmute {
  background-image: url(http://franriavilla.in/images/unmute.png);
  background-size: cover;
  width: 35px;
  height: 30px;
  cursor: pointer;
}

.mute {
  background-image: url(http://franriavilla.in/images/mute.png);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<audio id="track" autoplay="autoplay" loop="loop">
    <source src="audio/ThemePackNet.mp3" type="audio/ogg" />
</audio>

<div class='unmute' onclick="document.getElementById('track').muted = !document.getElementById('track').muted;$(this).toggleClass('mute')"></div>

于 2017-03-16T09:22:43.923 回答