11 jQuery events 1


#1

My sprite isn't moving

$(document).ready(function() {
$(document).keydown(function(key) {
switch(parseInt(key.which,10)) {
// Left arrow key pressed
case 37:
$('img').animate({left: "-=10px"}, 'fast');
break;
// Up Arrow Pressed
case 38:
$('img').animate({up: "+=10px"},'fast');
break;
// Right Arrow Pressed
case 39:
$('img').animate({right: "-=10px"}, 'fast');
break;
// Down Arrow Pressed
case 40:
$('img').animate({up: "-=10px"},'fast');// Put our code here
break;
}
});
});

Why isn't it working


#2

@webblaster43455,
Have a look at

https://www.codecademy.com/forum_questions/517d1061a1b9a94938003042


#3

Thanks Leonhard! My problem was that I wasn't clicking in the window near the sprite before pressing the arrows, as Matthew describes at the bottom of that link:

"If you are still having problems moving him around after you do the correct code mentioned above, make you click on or near Mario and then the keys will start moving him around."