WASD movement
HTML
<div class="target"></div>
CSS
.target {
position: relative;
left: 10;
top: 0;
width:50px;
height:50px;
background:blue;
-webkit-transition:all .2s ease-out;
-moz-transition:all .2s ease-out;
}
JavaScript
$(document).keydown(function (key) {
switch (parseInt(key.which, 10)) {
case 65: //a
$('.target').css({
left: "-=10px"
});
break;
case 83: //s
$('.target').css({
top: "+=10px"
});
break;
case 87: //w
$('.target').css({
top: "-=10px"
});
break;
case 68: //d
$('.target').css({
left: "+=10px"
});
break;
default:
break;
}
});