Skip to content

Commit

Permalink
Merge pull request #1197 from nepalivai/sound
Browse files Browse the repository at this point in the history
Added mute button.
  • Loading branch information
vikhyatsingh123 authored Dec 26, 2023
2 parents 1683ae8 + edb6e25 commit 00e5ffb
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
Binary file added adi image/sound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var nyan = document.getElementById("nyan");
var nyanBtn = document.getElementById("nyan-btn");

function playPause(song) {
if (song.paused && song.currentTime >= 0 && !song.ended) {
song.play();
} else {
song.pause();
}
}

function reset(btn, song) {
if (btn.classList.contains("playing")) {
btn.classList.toggle("playing");
}
song.pause();
song.currentTime = 0;
}

function progress(btn, song) {
setTimeout(function () {
var end = song.duration;
var current = song.currentTime;
var percent = current / (end / 100);
//check if song is at the end
if (current == end) {
reset(btn, song);
}
//set inset box shadow
btn.style.boxShadow =
"inset " +
btn.offsetWidth * (percent / 100) +
"px 0px 0px 0px rgba(0,0,0,0.125)";
//call function again
progress(btn, song);
}, 1000);
}

nyanBtn.addEventListener("click", function () {
nyanBtn.classList.toggle("playing");
playPause(nyan);
progress(nyanBtn, nyan);
});
13 changes: 9 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@
</script>
<script src='//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'></script>
</li>
</div>
</div>
<li>
<audio id="nyan" src="./sound/naruto.mp3" preload="metadata" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<a class="btn" id="nyan-btn">play / pause <img src="./adi image/sound.png" class="soundicon">
<script src="./audio.js"></script>
</a>
</li>
</ul>

</div>
Expand Down Expand Up @@ -3441,9 +3449,6 @@ <h1>Our Valuable Contributors</h1>
</div>
<script src="contributors.js"></script>


<audio src="./sound/naruto.mp3"></audio>

<footer class="footer">
Developed and Designed By <span id="idblink" onclick="tap()" style="cursor: pointer;"><u>Vikhyat
Singh</u></span> | ©
Expand Down
34 changes: 34 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -928,3 +928,37 @@ ul.navbar-nav.mr-auto {
.footer span {
text-decoration: underline;
}

.btn {
cursor: pointer;
display: inline-block;
background: #94a657;
border-radius: 4px;
color: #fff;
text-transform: uppercase;
line-height: 20px;
@include transition(box-shadow 0.25s ease);
&:after {
content: "";
display: inline-block;
color: #94a657;
background: #fff;
font-family: "FontAwesome";
padding: 3px;
border-radius: 50%;
height: 10px;
width: 10px;
margin-left: 8px;
padding-left: 4.5px;
padding-right: 1.5px;
}
&.playing {
&:after {
padding: 3px;
}
}
}
.soundicon {
width: 25px;
padding: 0px;
}

0 comments on commit 00e5ffb

Please sign in to comment.