-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainscript.js
50 lines (45 loc) · 1.33 KB
/
mainscript.js
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
'use strict';
function play(event) {
del();
let elements=document.querySelectorAll('[data-key]');
for (let i = 0; i < elements.length; i++){
let key=elements[i].getAttribute("data-key");
if (key==event.keyCode) {
elements[i].classList.add("showParty");
let audios=document.querySelectorAll("audio[data-key]");
for (let i = 0; i < audios.length; i++) {
if (audios[i].getAttribute("data-key")==key){
audios[i].currentTime=0;
audios[i].play();
console.log(audios[i].getAttribute("data-key"));
}
}
return;
}
}
};
function clear(event){
event.target.classList.remove("showParty");
}
function warning() {
let tip=document.getElementsByClassName("tip")[0];
if (!tip) {
let main=document.getElementsByClassName('container')[0];
let div=document.createElement("div");
let text="Use only keyboard according to above letters";
div.className="tip";
div.textContent=text;
//keys.parentNode.insertBefore(div, keys.nextSibling);
document.body.appendChild(div);
}
}
function del(){
let tip=document.getElementsByClassName("tip")[0];
if (tip) {
tip.remove();
}
return;
};
document.addEventListener("keydown",play);
document.addEventListener("transitionend",clear);
document.addEventListener("click",warning);