-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
51 lines (51 loc) · 1.37 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>key code</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrap">
<div data-key="65" class="no">
A
</div>
<div data-key="83" class="no">
S
</div>
<div data-key="68" class="no">
D
</div>
<div data-key="70" class="no">
F
</div>
</div>
<script>
function removeEffect(e) {
var remove_style;
if (e.which === 1) {
remove_style = this;
} else {
remove_style = document.querySelector(`div[data-key="${e.keyCode}"]`);
}
if (!remove_style) return;
remove_style.classList.remove('tap');
}
function keyboardKeyCode(e){
var insert;
if (e.which === 1) {
insert = this;
} else {
insert = document.querySelector(`div[data-key="${e.keyCode}"]`);
}
if (!insert) return;
insert.classList.add('tap');
}
window.addEventListener('keydown',keyboardKeyCode);
window.addEventListener('keyup',removeEffect);
const select_input = document.querySelectorAll('.no');
select_input.forEach(key => key.addEventListener('mousedown',keyboardKeyCode));
select_input.forEach(key => key.addEventListener('mouseup',removeEffect));
</script>
</body>
</html>