I'm trying to move a div using the arrow keys. I have the following code which is not working for me. Do you see anything wrong with it. Check jsfiddle at http://jsfiddle.net/N5Ltt/1/
$(document).keydown(function(e) {
switch (e.which) {
case 37:
$('div').stop().animate({
left: '-= 10'
}); //left arrow key
break;
case 38:
$('div').stop().animate({
top: '-= 10'
}); //up arrow key
break;
case 39:
$('div').stop().animate({
left: '+= 10'
}); //right arrow key
break;
case 40:
$('div').stop().animate({
top: '+= 10'
}); //bottom arrow key
break;
}
})
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…