I cannot move div by A, W, D, S keys

Hi,

I cannot move div by A, W, D, S keys: http://jsfiddle.net/8Observer8/mHAHz/128/

Thank you!

  1. You don’t match the right keys. It might be browser specific, not sure with jQuery, but mine are different than what you input.

  1. You do
$('square')

instead of

$('.square')

Gotta match the class, not a

<square>

  1. You need to add a ‘position’ attribute to the square’s css properties.

Try this: http://jsfiddle.net/mHAHz/130/

@thetenfold ;

cool.

Thank you very much! How to move continuously (very fast and continuously)?

What do you mean continuously? back and forth? Use window.setInterval to find when it gets to either side and have it fade the opposite way.

I want to move div how a “small car”.

I think this div needs to be moved like Link in Legend of Zelda. So instead, he probably needs to listen for repeated key events as the key is held down (the key keeps making new events while it is held down?).

Probably the script is slow because for each key it’s findgin .square again and again. It should be faster if .square is found once and saved into a variable. Before document.onkeydown event listener.

http://stackoverflow.com/questions/4950575/how-to-move-a-div-with-arrow-keys

Thank you very much! This is the example from your link: http://jsfiddle.net/bDMnX/7/ I wanted to make this. Thanks!