-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
153 lines (133 loc) · 3.82 KB
/
script.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
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
// Elements
const words = document.querySelectorAll(".words");
const pad = document.querySelector('.pad');
const title = document.querySelector('.title');
const elm_pad_one = document.querySelector('.pad-1');
const elm_pad_two = document.querySelector('.pad-2');
const elm_pad_three = document.querySelector('.pad-3');
const elm_pad_four = document.querySelector('.pad-4');
const elm_pad_five = document.querySelector('.pad-5');
const elm_pad_six = document.querySelector('.pad-6');
const elm_pad_seven = document.querySelector('.pad-7');
const elm_pad_eight = document.querySelector('.pad-8');
const elm_pad_nine = document.querySelector('.pad-9');
const elm_pad_ten = document.querySelector('.pad-10');
const elm_pad_eleven = document.querySelector('.pad-11');
const elm_pad_twelve = document.querySelector('.pad-12');
// Const variables
const elm_pads = [
elm_pad_one,
elm_pad_two,
elm_pad_three,
elm_pad_four,
elm_pad_five,
elm_pad_six,
elm_pad_seven,
elm_pad_eight,
elm_pad_nine,
elm_pad_ten,
elm_pad_eleven,
elm_pad_twelve
];
const pad_one = new Audio('audio/1.mp3');
const pad_two = new Audio('audio/2.mp3');
const pad_three = new Audio('audio/3.mp3');
const pad_four = new Audio('audio/4.mp3');
const pad_five = new Audio('audio/5.mp3');
const pad_six = new Audio('audio/6.mp3');
const pad_seven = new Audio('audio/7.mp3');
const pad_eight = new Audio('audio/8.mp3');
const pad_nine = new Audio('audio/9.mp3');
const pad_ten = new Audio('audio/10.mp3');
const pad_eleven = new Audio('audio/11.mp3');
const pad_twelve = new Audio('audio/12.mp3');
const pads = [
pad_one,
pad_two,
pad_three,
pad_four,
pad_five,
pad_six,
pad_seven,
pad_eight,
pad_nine,
pad_ten,
pad_eleven,
pad_twelve
];
var firstTime = true;
// Function
const play = (pad_index) => {
if (!pads[pad_index - 1]) return;
pads[pad_index - 1].load();
pads[pad_index - 1].play();
};
// Events
elm_pads.forEach(pad => {
pad.addEventListener('click', () => {
play(pad.dataset.pad);
});
});
function showWords() {
var afterTime = 700;
for (var i = 0; i < words.length; i++) {
(function (i) {
setTimeout(function(){
words[i].style.opacity = 1;
}, afterTime);
afterTime+=200;
}).call(this, i);
}
}
showWords();
function hideWords() {
var afterTime = 700;
for (var i = words.length-1; i >= 0; i--) {
(function (i) {
setTimeout(function(){
words[i].style.opacity = 0;
}, afterTime);
afterTime+=200;
}).call(this, i);
}
}
function showOtherWords() {
for (var i = 2; i < words.length; i++) {
words[i].style.display = "none";
}
words[0].textContent = "Have";
words[1].textContent = "fun!";
showWords();
setTimeout(hideWords, 500);
setTimeout(
title.style.opacity=1,
pad.style.opacity=1,
pad.style.pointerEvent=all
, 2000);
}
setTimeout(function(){
document.querySelector(".github").style.opacity = 1;
}, 500);
document.addEventListener('keydown', (e) => {
if (firstTime) {
setTimeout(hideWords, 500);
setTimeout(showOtherWords, 2500);
firstTime = false;
}
const key = String.fromCharCode(e.keyCode);
const box = document.querySelector(`div[data-key='${key}']`);
if (!box) return;
box.classList.add("active");
const Drum_keys = [
"R", "T", "Y", "U",
"F", "G", "H", "J",
"V", "B", "N", "M"
];
if (Drum_keys.includes(key)) play(Drum_keys.indexOf(key) + 1);
});
document.addEventListener('keyup', (e) => {
const key = String.fromCharCode(e.keyCode);
const box = document.querySelector(`div[data-key='${key}']`);
if (!box) return;
box.classList.remove("active");
});