I made this script to move a div by pressing the arrow keys. The right and bottom keys are working perfectly, however, the top and left are not, the code is the same as the others.
Follow the code below:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(document).keydown(function(x){
if(x.which == 39 || x.keyCode == 39){
$('div').animate({left: '1180px'});
}
}).keyup(function(){
$('div').animate().stop();
});
});
$(document).ready(function(){
$(document).keydown(function(x){
if(x.which == 40 || x.keyCode == 40){
$('div').animate({top: '1180px'});
}
}).keyup(function(){
$('div').stop();
});
});
$(document).ready(function(){
$(document).keydown(function(x){
if(x.which == 37 || x.keyCode == 37){
$('div').animate({right: '1180px'});
}
}).keyup(function(){
$('div').stop();
});
});
$(document).ready(function(){
$(document).keydown(function(x){
if(x.which == 38 || x.keyCode == 38){
$('div').animate({ '1180px'});
}
}).keyup(function(){
$('div').stop();
});
});
</script>