JSFiddle - React, Tailwind, and code Playground

by Vamsi krishna mannem

HTML

<div>vamsi</div>

CSS

div{
    height:50px;
    background:#f00;
    width:100px;
    position:absolute;
}

JavaScript

$(document).ready(function(){
$('body').keydown(function(event) {
    console.log(event.which);
    
if (event.which == 38)
        {
            $('div').animate({top:'+=10px'},'fast');
        }
        else if (event.which == 40)
        {
            $('div').animate({top:'+=10px'},'fast');
        }
        else if (event.which == 37)
        {
            $('div').animate({left:'-=10px'},'fast');
        }
        else if (event.which == 39)
        {
            $('div').animate({left:'+=10px'},'fast');
        }
}); 
});