First of all, why is the pause?
effect: Use the keyboard to control a DIV move
When you press one of the arrow keys, the div pauses before starting to move continuously.
Reason: the system to distinguish whether the user is continuous input, the first to the second between there is a pause time
Note: Understand the reason to solve the problem
Effect Show
1. Simple control, but there is a pause
2. Simple control, solve the pause
Solving method
method: first open a timer, so that Div has been in (in 4 directions) ready to move the state
The initial 4-direction values are false,div and remain stationary.
When you press a direction key, the value in this direction changes to True,div will start moving in this direction.
When you release the arrow key, the value in this direction changes to false, and the div stops moving in that direction.
basic move, but there's a nice bit of code
control movement, solve the problem of a pause
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's work or learning can bring certain help, if you have questions you can message exchange.