-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
117 lines (111 loc) · 3.82 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Do Re Mi</title>
<link rel="stylesheet" href="style.css">
<style media="screen">
.image {
background-image: url(piano.jpg);
background-repeat:no-repeat;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
background-position:center;
}
.keys {
display: flex;
flex-direction: row;
justify-content: space-around;
height: 100vh;
align-items: center;
}
.key {
border: 2px solid #fff;
padding: 15px;
color: #D0D0D0;
font-family: roboto;
border-radius: 5px;
text-align: center;
transition: all 0.5s;
background: rgba(0,0,0,0.4);
text-shadow: 0 0 5px black;
}
.playing {
transform: scale(1.1);
border-color: yellow;
box-shadow: 0 0 10px yellow;
}
kbd {
display: block;
font-size: 3em;
}
.sound {
font-size: 1em;
color: yellow;
}
</style>
</head>
<body class="image">
<div class="keys">
<div data-key="90" class="key">
<kbd>Z</kbd>
<span class="sound">DO</span>
</div>
<div data-key="88" class="key">
<kbd>X</kbd>
<span class="sound">RE</span>
</div>
<div data-key="67" class="key">
<kbd>C</kbd>
<span class="sound">MI</span>
</div>
<div data-key="86" class="key">
<kbd>V</kbd>
<span class="sound">FA</span>
</div>
<div data-key="66" class="key">
<kbd>B</kbd>
<span class="sound">SOL</span>
</div>
<div data-key="78" class="key ">
<kbd>N</kbd>
<span class="sound">LA</span>
</div>
<div data-key="77" class="key">
<kbd>M</kbd>
<span class="sound">SI</span>
</div>
<div data-key="76" class="key">
<kbd>L</kbd>
<span class="sound">DO ^</span>
</div>
</div>
<audio data-key="90" src="sounds/1do.wav"></audio>
<audio data-key="88" src="sounds/2re.wav"></audio>
<audio data-key="67" src="sounds/3mi.wav"></audio>
<audio data-key="86" src="sounds/4fa.wav"></audio>
<audio data-key="66" src="sounds/5sol.wav"></audio>
<audio data-key="78" src="sounds/6la.wav"></audio>
<audio data-key="77" src="sounds/7si.wav"></audio>
<audio data-key="76" src="sounds/8do.wav"></audio>
<script type="text/javascript">
function playSound(e) {
var audio = document.querySelector (`audio[data-key= "${e.keyCode}"]`);
var key = document.querySelector (`.key[data-key= "${e.keyCode}"]`);
if(!audio) return; // if no audio stop function from running
audio.currentTime = 0; //rewind to the start
audio.play();
key.classList.add('playing');
}
function removeTransform(e) {
if(e.propertyName !== 'transform') return; //skip it if it's not a transform
this.classList.remove('playing');
}
var keys = document.querySelectorAll('.key');
keys.forEach(key => key.addEventListener('transitionend', removeTransform));
window.addEventListener("keydown",playSound);
</script>
</body>
</html>