Jquery 11 filling out the cases


#1

Maybe I am missing something would love some help

$(document).ready(function() {
$(document).keydown(function(key) {
switch(parseInt(key.which,10)) {
case 37:
$('img').animate({left:"-=10px"}, 'fast');
break;
case 38:
$('img').animate({top:"-=10px"}, 'fast');
break;
case 39:
$('img').animate({right:"+=10px"}, 'fast');
break;
case 40:
$('img').animate({down:"+=10px"}, 'fast');
break;
}
});
});

I thought I had everything correct, but when i go the page and click to arrows its only moves left and up. Not sure what is wrong.


#2

Aniimation is relative to the top and left axes.

top: "-=10px"   => up
top: "+=10px"   => down

left: "-=10px"  => left
left: "+=10px"  => right

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.