In fact, this example uses two core times of js, the keyboard event onkeydown and the periodic execution event setInterval.
When a certain key on the keyboard is pressed, the characters on the web page will perform corresponding actions, achieving the effect of using the keyboard to control movement
1. Function of reservation key:
a: to the left
2. After booking the key value, it is necessary to capture the key event and determine which key the user pressed?
To capture keyboard events you can use onkeydown
To obtain the key-value code, you can use event.keyCode
3. Use setInterval periodic execution event to replace the picture
Replacing pictures is to achieve the task walking effect
But be careful to use clearInterval to clear the cycle execution, otherwise it will go faster and faster