我已经了解了如何<audio>
通过输入以下代码来使声音对象静音:
<a href="#" onclick="document.getElementById('ambiance').muted = true; return false">
mute sound
</a>
现在我正在搜索如何使用带有切换选项的相同按钮来静音/取消静音我的声音?
谁能给我指路?
我已经了解了如何<audio>
通过输入以下代码来使声音对象静音:
<a href="#" onclick="document.getElementById('ambiance').muted = true; return false">
mute sound
</a>
现在我正在搜索如何使用带有切换选项的相同按钮来静音/取消静音我的声音?
谁能给我指路?
var audioElm = document.getElementById('ambiance'); audioElm.muted = !audioElm.muted;
尝试这个:
.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>