Last active
July 20, 2020 04:11
-
-
Save shimajima-eiji/a3077686179f1c298e6cc1d4845554bf to your computer and use it in GitHub Desktop.
gist連携
この下にキーに対応した文字列を表示させる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const OUTPUT_ID = "displayArea", | |
cursor = { | |
ArrowUp: "↑", | |
ArrowDown: "↓", | |
ArrowLeft: "←", | |
ArrowRight: "→", | |
}; | |
document.onkeydown = keydown; | |
function keydown(e) { | |
document.getElementById(OUTPUT_ID).textContent = cursor[e.key] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.onkeydown = keydown; | |
function keydown() { | |
if (event.key == "ArrowUp") { | |
document.getElementById("displayArea").textContent = "↑"; | |
} else if (event.key == "ArrowDown") { | |
document.getElementById("displayArea").textContent = "↓"; | |
} else if (event.key == "ArrowLeft") { | |
document.getElementById("displayArea").textContent = "←"; | |
} else if (event.key == "ArrowRight") { | |
document.getElementById("displayArea").textContent = "→"; | |
} else { | |
document.getElementById("displayArea").textContent = event.key; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p { | |
font-size:20px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment