Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7417d25

Browse files
committed
finished the drum but cleanup needed and improvement
1 parent c2b9d55 commit 7417d25

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

01 - JavaScript Drum Kit/drumKit.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
window.addEventListener('keydown', function(e){
2-
console.log(e);
3-
})
2+
const audio = document.querySelector(`audio[data-key='${e.keyCode}']`);
3+
const key = document.querySelector(`.key[data-key='${e.keyCode}']`);
4+
if(!audio) return;
5+
// console.log(audio);
6+
audio.currentTime = 0; //for rewind
7+
audio.play();
8+
key.classList.add('playing');
9+
});
10+
11+
function removeTransition(e){
12+
// console.log(e.propertyName);
13+
if(e.propertyName !== 'transform') return;
14+
// console.log(this); // refers to the key event which it triggered
15+
this.classList.remove('playing');
16+
}
17+
18+
const keys = document.querySelectorAll('.key');
19+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));

01 - JavaScript Drum Kit/learning.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ Things learnt while solving this project
22

33
1: learnt css property transform, translate, skew, scale, rotate.
44
2: learnt css property box-shadow.
5-
3: DOM Events
5+
3: DOM KeyEvents AudioEvents and Transistion
6+
7+
// TODO
8+
1: Build own CSS
9+

0 commit comments

Comments
 (0)