Skip to content

Commit ebee36e

Browse files
author
devbyali
committed
mute sounds
1 parent 107803f commit ebee36e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

app.js

+35
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DrumKit {
1212
this.bpm = 150;
1313
this.isPlaying = null;
1414
this.selects = document.querySelectorAll("select");
15+
this.muteBtn = document.querySelectorAll(".mute");
1516
}
1617
activePad() {
1718
this.classList.toggle("active");
@@ -81,6 +82,35 @@ class DrumKit {
8182
break;
8283
}
8384
}
85+
mute(e) {
86+
const muteIndex = e.target.getAttribute("data-track");
87+
e.target.classList.toggle("active");
88+
if (e.target.classList.contains("active")) {
89+
switch (muteIndex) {
90+
case "0":
91+
this.KickAudio.volume = 0;
92+
break;
93+
case "1":
94+
this.snareAudio.volume = 0;
95+
break;
96+
case "2":
97+
this.hihatAudio.volume = 0;
98+
break;
99+
}
100+
} else {
101+
switch (muteIndex) {
102+
case "0":
103+
this.KickAudio.volume = 1;
104+
break;
105+
case "1":
106+
this.snareAudio.volume = 1;
107+
break;
108+
case "2":
109+
this.hihatAudio.volume = 1;
110+
break;
111+
}
112+
}
113+
}
84114
}
85115
const drumKit = new DrumKit();
86116

@@ -101,3 +131,8 @@ drumKit.selects.forEach((select) => {
101131
drumKit.changeSound(e);
102132
});
103133
});
134+
drumKit.muteBtn.forEach((btn) => {
135+
btn.addEventListener("click", (e) => {
136+
drumKit.mute(e);
137+
});
138+
});

style.css

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ select {
110110
font-size: 1rem;
111111
}
112112

113+
.mute.active {
114+
background: rgb(182, 182, 182);
115+
color: white;
116+
}
117+
113118
@keyframes playTrack {
114119
from {
115120
transform: scale(1);

0 commit comments

Comments
 (0)