2011-10-17 242 views
2

我已經明白瞭如何把這個代碼靜音的<audio>聲音對象:靜音和取消靜音按鈕切換HTML5音頻,

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

現在我在尋找如何靜音/使用與同一按鈕取消靜音我的聲音切換它的選項?

任何人都可以給我方向嗎?

回答

7
var audioElm = document.getElementById('ambiance'); audioElm.muted = !audioElm.muted; 
+0

大非常感謝你。 – numerosept

0

試試吧

https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
.unmute{ 
 
\t \t \t background-image: url(http://franriavilla.in/images/unmute.png); 
 
\t \t \t background-size: cover; 
 
\t \t \t width:35px; 
 
\t \t \t height:30px; 
 
\t \t \t cursor: pointer; 
 
\t \t } 
 

 
\t \t .mute{ 
 
\t \t \t background-image: url(http://franriavilla.in/images/mute.png); 
 
\t \t }
<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>