JSFiddle - React, Tailwind, and code Playground
by Amar Nyayapati
HTML
<div id="snake"></div>
<script>
$(document).bind('keydown', function(e) {
var box = $("#snake"),
left = 37,
up = 38,
right = 39,
down = 40
if (e.keyCode == left) {
box.css("left", "-=5");
}
if (e.keyCode == up) {
box.css("top", "-=5");
}
if (e.keyCode == right) {
box.css("left", "+=5");
}
if (e.keyCode == down) {
box.css("top", "+=5");
}
});
</script>
CSS
#snake{
width:30px;
height:30px;
background:green;
position:absolute;
top:40%;
left:40%;
}