11 jQuery events 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');
// Up Arrow Pressed
case 38:
$('img').animate({up: "+=10px"},'fast');
// Right Arrow Pressed
case 39:
$('img').animate({right: "-=10px"}, 'fast');
// Down Arrow Pressed
case 40:
$('img').animate({up: "-=10px"},'fast');// Put our code here

Why isn't it working


Have a look at



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."