forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall.js
More file actions
44 lines (40 loc) · 1.09 KB
/
all.js
File metadata and controls
44 lines (40 loc) · 1.09 KB
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
'use strict';
/**
* Created by ale on 27/12/17.
*/
var play = function play(e) {
console.log(e);
var el = void 0;
if (e.type === 'click') {
// console.log(e.target.parentNode);
var key = e.target.parentNode;
var audio = key.querySelector('audio');
key.classList.add('playing');
audio.currentTime = 0;
audio.play();
} else {
if (el = document.querySelector('div[data-key="' + e.keyCode + '" ]')) {
el.classList.add("playing");
var _audio = el.querySelector("audio");
_audio.currentTime = 0;
_audio.play();
}
}
};
window.addEventListener('keyup', function (e) {
play(e);
});
var allKeys = document.querySelectorAll('.key');
console.log(allKeys);
var allArr = Array.from(allKeys);
allArr.map(function (key) {
key.addEventListener('click', function (e) {
return play(e);
});
});
window.addEventListener('transitionend', function (e) {
if (e.propertyName === 'transform') {
e.target.classList.remove('playing');
}
});
//# sourceMappingURL=all.js.map