- Joined
- Jun 2, 2023
- Messages
- 2
- Reaction score
- 0
I'm trying to code a mute button that corresponds to a volume slider for a project I'm working on. Currently, I'm trying to make the mute & unmute buttons have different images but it isn't working. Can anyone tell me why?
Here is my code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.slidecontainer {
height: 5px;
width: -5px;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 100%;
max-width: 200px;
background: #d3d3d3;
outline: none;
opacity: 1;
-webkit-transition: .2s;
transition: opacity .2s;
transform: rotate(90deg);
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 5px;
height: 20px;
background: #04AA6D;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
#imageButton {
width: 90px; /* Adjust the width as desired */
height: 70px; /* Adjust the height as desired */
border: 0px solid #000; /* Adjust the border width and color as desired */
border-radius: 0px; /* Adjust the border radius as desired */
display: inline-block; /* Ensure the button retains its dimensions */
overflow: hidden; /* Ensures the image fits within the button */
position: relative; /* Position the icons */
cursor: pointer; /* Add cursor pointer to indicate clickability */
}
#imageButton img {
width: 100%;
height: 100%;
object-fit: cover; /* Preserve aspect ratio of the image within the button */
}
#muteIcon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: block; /* Initially visible */
}
#unmuteIcon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none; /* Initially hidden */
}
</style>
</head>
<body>
<br>
<br>
<br>
<br>
<div class="slidecontainer">
<input type="range" min="0" max="1" step="0.05" value="0.5" class="slider" id="myRange">
</div>
<audio id="myAudio" src="path/to/audio.mp3" type="audio/mpeg"></audio>
<button id="imageButton" type="button" onclick="toggleMute()">
<img id="muteIcon" src="C:\Users\PCNAMEPLACEHOLDER\Downloads\ERMEGBkU0AAr_L9.jpg" alt="Mute Icon">
<img id="unmuteIcon" src="C:\Users\PCNAMEPLACEHOLDER\Downloads\image.jpg" alt="Unmute Icon">
</button>
<script>
var slider = document.getElementById("myRange");
var audio = document.getElementById("myAudio");
var imageButton = document.getElementById("imageButton");
var muteIcon = document.getElementById("muteIcon");
var unmuteIcon = document.getElementById("unmuteIcon");
var isMuted = false;
// Function to toggle mute/unmute and update icons
function toggleMute()
Here is my code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.slidecontainer {
height: 5px;
width: -5px;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 100%;
max-width: 200px;
background: #d3d3d3;
outline: none;
opacity: 1;
-webkit-transition: .2s;
transition: opacity .2s;
transform: rotate(90deg);
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 5px;
height: 20px;
background: #04AA6D;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
#imageButton {
width: 90px; /* Adjust the width as desired */
height: 70px; /* Adjust the height as desired */
border: 0px solid #000; /* Adjust the border width and color as desired */
border-radius: 0px; /* Adjust the border radius as desired */
display: inline-block; /* Ensure the button retains its dimensions */
overflow: hidden; /* Ensures the image fits within the button */
position: relative; /* Position the icons */
cursor: pointer; /* Add cursor pointer to indicate clickability */
}
#imageButton img {
width: 100%;
height: 100%;
object-fit: cover; /* Preserve aspect ratio of the image within the button */
}
#muteIcon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: block; /* Initially visible */
}
#unmuteIcon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none; /* Initially hidden */
}
</style>
</head>
<body>
<br>
<br>
<br>
<br>
<div class="slidecontainer">
<input type="range" min="0" max="1" step="0.05" value="0.5" class="slider" id="myRange">
</div>
<audio id="myAudio" src="path/to/audio.mp3" type="audio/mpeg"></audio>
<button id="imageButton" type="button" onclick="toggleMute()">
<img id="muteIcon" src="C:\Users\PCNAMEPLACEHOLDER\Downloads\ERMEGBkU0AAr_L9.jpg" alt="Mute Icon">
<img id="unmuteIcon" src="C:\Users\PCNAMEPLACEHOLDER\Downloads\image.jpg" alt="Unmute Icon">
</button>
<script>
var slider = document.getElementById("myRange");
var audio = document.getElementById("myAudio");
var imageButton = document.getElementById("imageButton");
var muteIcon = document.getElementById("muteIcon");
var unmuteIcon = document.getElementById("unmuteIcon");
var isMuted = false;
// Function to toggle mute/unmute and update icons
function toggleMute()