I wanted the element to move along the arrow using .css (), but it doesn’t work at all, and I cannot understand why. Exactly the same code works fine with JQ animate (). Can you explain to me why .css is not working? I know there are better ways to do this, but I'm just wondering why it doesn't attach the top property. Below is the animation code
$(document).ready(function(){
$('body').keydown(function() {
if (event.which == 38)
{
$('div').animate({top:'-=10px'},'fast');
}
else if (event.which == 40)
{
$('div').animate({top:'+=10px'},'fast');
}
else if (event.which == 37)
{
$('div').animate({left:'-=10px'},'fast');
}
else if (event.which == 39)
{
$('div').animate({left:'+=10px'},'fast');
}
});
});
tslid source
share