Filling Out the Cases


#1

I got through the exercise but I just wanted to ask why doesn't my code work when in order to move right, I subtract 10px from the right instead of adding 10px to the left?

Was just experimenting so a doubt came in my mind....

$(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({top: "-=10px"}, 'fast');
				break;
			// Right Arrow Pressed
			case 39:
				$('img').animate({right: "-=10px"}, 'fast');
				break;
			// Down Arrow Pressed
			case 40:
				$('img').animate({top: "+=10px"}, 'fast');
				break;
		}
	});
});

#2

.animate() takes only top and left axes of reference. Change the direction and use the one for vertical or horizontal translation, respectively.


#3

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