-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
230 lines (217 loc) · 7.11 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Music Smash</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!--Q=81
W=87
E=69
R=82
T=84
Y=89
U=85
I=73
O=79
P=80
A=65
S=83
D=68
F=70
G=71
H=72
J=74
K=75
L=76
Ñ=192
Z=90
X=88
C=67
V=86
B=66
N=78
M=77
-->
<div style="height: 25vh"></div>
<!--This is just so it takes space and the keys are not as separated :p-->
<div class="keys">
<div data-key="81" class="key">
<kbd>Q</kbd>
<span class="sound">Note</span>
</div>
<div data-key="87" class="key">
<kbd>W</kbd>
<span class="sound">Violin</span>
</div>
<div data-key="69" class="key">
<kbd>E</kbd>
<span class="sound">Bird</span>
</div>
<div data-key="82" class="key">
<kbd>R</kbd>
<span class="sound">Page</span>
</div>
<div data-key="84" class="key">
<kbd>T</kbd>
<span class="sound">Roar</span>
</div>
<div data-key="89" class="key">
<kbd>Y</kbd>
<span class="sound">Whistle</span>
</div>
<div data-key="85" class="key">
<kbd>U</kbd>
<span class="sound">Sweep</span>
</div>
<div data-key="73" class="key">
<kbd>I</kbd>
<span class="sound">Deep</span>
</div>
<div data-key="79" class="key">
<kbd>O</kbd>
<span class="sound">Happy</span>
</div>
<div data-key="80" class="key">
<kbd>P</kbd>
<span class="sound">Magnet</span>
</div>
</div>
<div class="keys">
<div data-key="65" class="key">
<kbd>A</kbd>
<span class="sound">Alert</span>
</div>
<div data-key="83" class="key">
<kbd>S</kbd>
<span class="sound">Punch</span>
</div>
<div data-key="68" class="key">
<kbd>D</kbd>
<span class="sound">Bike</span>
</div>
<div data-key="70" class="key">
<kbd>F</kbd>
<span class="sound">Car</span>
</div>
<div data-key="71" class="key">
<kbd>G</kbd>
<span class="sound">Chord</span>
</div>
<div data-key="72" class="key">
<kbd>H</kbd>
<span class="sound">Cup</span>
</div>
<div data-key="74" class="key">
<kbd>J</kbd>
<span class="sound">Doorbell</span>
</div>
<div data-key="75" class="key">
<kbd>K</kbd>
<span class="sound">Drum</span>
</div>
<div data-key="76" class="key">
<kbd>L</kbd>
<span class="sound">Fall</span>
</div>
<div data-key="192" class="key">
<kbd>Ñ</kbd>
<span class="sound">Woosh</span>
</div>
</div>
<div class="keys">
<div data-key="90" class="key">
<kbd>Z</kbd>
<span class="sound">Wood</span>
</div>
<div data-key="88" class="key">
<kbd>X</kbd>
<span class="sound">Water</span>
</div>
<div data-key="67" class="key">
<kbd>C</kbd>
<span class="sound">Bell</span>
</div>
<div data-key="86" class="key">
<kbd>V</kbd>
<span class="sound">Train</span>
</div>
<div data-key="66" class="key">
<kbd>B</kbd>
<span class="sound">Bass</span>
</div>
<div data-key="78" class="key">
<kbd>N</kbd>
<span class="sound">Guitar</span>
</div>
<div data-key="77" class="key">
<kbd>M</kbd>
<span class="sound">Flute</span>
</div>
</div>
<audio data-key="65" src="Sounds/alert.wav"></audio>
<audio data-key="66" src="Sounds/bass.wav"></audio>
<audio data-key="67" src="Sounds/bell.wav"></audio>
<audio data-key="68" src="Sounds/bike.wav"></audio>
<audio data-key="69" src="Sounds/bird.wav"></audio>
<audio data-key="70" src="Sounds/car.wav"></audio>
<audio data-key="71" src="Sounds/chord.wav"></audio>
<audio data-key="72" src="Sounds/cup.wav"></audio>
<audio data-key="73" src="Sounds/deep.wav"></audio>
<audio data-key="74" src="Sounds/doorbell.wav"></audio>
<audio data-key="75" src="Sounds/drum.wav"></audio>
<audio data-key="76" src="Sounds/fall.wav"></audio>
<audio data-key="77" src="Sounds/flute.wav"></audio>
<audio data-key="78" src="Sounds/guitar.wav"></audio>
<audio data-key="79" src="Sounds/happy.wav"></audio>
<audio data-key="80" src="Sounds/Magnet.wav"></audio>
<audio data-key="81" src="Sounds/note.wav"></audio>
<audio data-key="82" src="Sounds/page.wav"></audio>
<audio data-key="83" src="Sounds/punch.wav"></audio>
<audio data-key="84" src="Sounds/roar.wav"></audio>
<audio data-key="85" src="Sounds/sweep.wav"></audio>
<audio data-key="86" src="Sounds/train.wav"></audio>
<audio data-key="87" src="Sounds/violin.wav"></audio>
<audio data-key="88" src="Sounds/water.wav"></audio>
<audio data-key="89" src="Sounds/whistle.wav"></audio>
<audio data-key="90" src="Sounds/wood.wav"></audio>
<audio data-key="192" src="Sounds/woosh.wav"></audio>
<script>
//With this the sound is played and the key starts its animation
function playSound(e){
const audio = document.querySelector(`audio[data-key ="${e}"]`); //audio element with data-key equal to code
const key = document.querySelector(`.key[data-key="${e}"]`); //key class with data-key equal to code
//console.log(e);
if (audio){
audio.currentTime = 0; //Restart the time for sound
audio.play();
key.classList.add("playing"); //Start the animation
}
}
//This is used when the keyboard is used
function keyPlay(e){
playSound(e.keyCode);
}
function removeTransition(e) {
if (e.propertyName !== "transform") return //skip if not a transform
this.classList.remove("playing") //Stop the animation
}
const keys = document.querySelectorAll(".key")
keys.forEach(function(key){
key.addEventListener("click",function(event){
playSound(this.getAttribute('data-key')); //Play when clicked
})
key.addEventListener("transitionend", removeTransition); //If the key transitioned, we remove it
/*if ("playing" in key.classList){
key.classList.remove("playing") //Aparently this workaround doesn't work, sooo the bug will be still there
}*/
//keys.forEach(key => key.addEventListener("click"),playSound);
}
)
window.addEventListener("keydown", keyPlay) //Play when the keyboard is pressed
</script>
</body>
</html>