feat: add button click effect

This commit is contained in:
2024-07-21 19:06:07 +01:00
parent bf9b2b8bb3
commit 0a937461f1
2 changed files with 15 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
const playBtn = document.getElementById("play-btn");
const catImg = document.getElementsByClassName("cat")[0];
const clickAudio = new Audio("/audio/click.wav");
const clickReleaseAudio = new Audio("/audio/click-release.wav");
const CROSSFADE_DURATION_MS = 5000;
const CROSSFADE_INTERVAL_MS = 20;
@@ -81,6 +83,17 @@ function animateCat() {
}, 500);
}
playBtn.onmousedown = () => {
clickAudio.play();
document.addEventListener(
"mouseup",
() => {
clickReleaseAudio.play();
},
{ once: true },
);
};
playBtn.onclick = () => {
if (isPlaying) {
pauseAudio();