-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
55 lines (49 loc) · 1.21 KB
/
utils.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
/**
* Beat class that keeps track of playing the audio
*/
class Beat {
constructor(audioSrc) {
this.audio = new Audio(audioSrc);
}
play = () => {
this.audio.currentTime = 0;
this.audio.play();
};
}
/**
* Button class that keeps track of the button color based on a press
*/
class Button {
constructor(color, keyCode) {
this.color = color;
this.keyCode = keyCode;
this.element = document.getElementById(keyCode);
this.setButtonColorInHTML();
this.setAtTransitionEndListener();
}
setAtTransitionEndListener = () => {
this.element.addEventListener("transitionend", () => {
this.deselect();
});
};
/**
* Set the button color based on color specified
*/
setButtonColorInHTML = () => {
this.element.style.borderColor = this.color;
};
/**
* Select function to set the background color and boxShadow
*/
select = () => {
this.element.style.backgroundColor = this.color;
this.element.style.boxShadow = `0px 0px 17px 0px ${this.color}`;
};
/**
* Deselect function to reset background color and boxShadow
*/
deselect = () => {
this.element.style.backgroundColor = "transparent";
this.element.style.boxShadow = "none";
};
}