admin管理员组文章数量:1318572
I was creating a website, I put background music, and my problem is I dont know how to create a button(only one) for mute/unmute the sound. I would like to have a mute button that can mute/unmute depending on the situation(if the music is muted then the button should have the image of a Loudspeaker,for hearing the sound, if you press it then you begin listening the music and the image of the button changes and vice versa)
what I have now is this:
<td width=10% valign="top" align="right">
<img src="images/sonidoON.png" onclick="this.src='images/sonidoOFF.png'" width=30% height=7%>
</td>
I only need to know how to create that button, not the functions for the background music.
Thank you very much in advance
I was creating a website, I put background music, and my problem is I dont know how to create a button(only one) for mute/unmute the sound. I would like to have a mute button that can mute/unmute depending on the situation(if the music is muted then the button should have the image of a Loudspeaker,for hearing the sound, if you press it then you begin listening the music and the image of the button changes and vice versa)
what I have now is this:
<td width=10% valign="top" align="right">
<img src="images/sonidoON.png" onclick="this.src='images/sonidoOFF.png'" width=30% height=7%>
</td>
I only need to know how to create that button, not the functions for the background music.
Thank you very much in advance
Share Improve this question edited Feb 4, 2022 at 10:51 VLAZ 29.1k9 gold badges63 silver badges84 bronze badges asked Apr 7, 2014 at 16:40 user3507245user3507245 111 gold badge1 silver badge2 bronze badges 1-
1
How are you playing the sound? Just a
bgsound
tag? – Bill the Lizard Commented Apr 7, 2014 at 16:51
2 Answers
Reset to default 3HTML
<input type="checkbox" name="un-mute" id="un-mute">
<label for="un-mute" class="unmute">
<img src="http://upload.wikimedia/wikipedia/mons/3/3f/Mute_Icon.svg" alt="Mute_Icon.svg" title="Mute icon">
</label>
<label for="un-mute" class="mute">
<img src="http://upload.wikimedia/wikipedia/mons/2/21/Speaker_Icon.svg" alt="Speaker_Icon.svg" title="Unmute/speaker icon">
</label>
CSS
input#un-mute {
display: none;
}
.unmute img {
display: none;
}
input#un-mute:checked ~ .unmute img {
display: initial;
}
input#un-mute:checked ~ .mute img {
display: none;
}
JavaScript
var un_mute = document.getElementById('un-mute');
un_mute.onclick = function() {
alert('toggle player here');
};
http://jsfiddle/Ffccv/2/
using :checked pseudo-class selector
You can do this To toggle them
<script>
function toggleSound(img)
{
img.src= img.src=="images/sonidoON.png" ? "images/sonidoOFF.png" : "images/sonidoON.png";
}
</script>
and onclick="toggleSound(this);"
or create img from script and use addEventListener ("click",toggleSound())
<td width=10% valign="top" align="right">
<img src="images/sonidoON.png" onclick="toggleSound(this);" width=30% height=7%>
</td>
fiddle demo : http://jsfiddle/K9553/
本文标签: javascriptHow to create a only muteunmute button (like youtube) in htmlStack Overflow
版权声明:本文标题:javascript - How to create a only muteunmute button (like youtube) in html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742048709a2417945.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论