javascript - Functionality Issue using the '.animate()' Function -
i working through jquery curriculum on codecademy , particular assignment involves using switch function in conjunction multiple instances of '.animate()' function. 'img' in question our favorite italian plumber move left. when run code error returned " oops, try again. looks image doesn't move right when press 'right'."
$(document).ready(function() { $(document).keydown(function(key) { switch(parseint(key.which,10)) { // left arrow key pressed case 37: $('img').animate({left: "-=10px"}, 'fast'); break; // 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({down: "-=10px"}, 'fast'); break; } }); });
$(document).ready(function () { $(document).keydown(function (key) { switch (parseint(key.which, 10)) { // left arrow key pressed case 37: $('img').animate({left: "-=10px"}, 'fast'); break; // arrow pressed case 38: $('img').animate({top: "-=10px"}, 'fast'); break; // right arrow pressed case 39: $('img').animate({left: "+=10px"}, 'fast'); break; // down array pressed case 40: $('img').animate({top: "+=10px"}, 'fast'); break; } }); });
try using left , top instead or else youll haunted css demons. , works don'nt invert up/down! :)
Comments
Post a Comment