In the following web we handle a square of red color that will be able to be displaced along the screen according to the pressed buttons arrow of the keyboard.
We create the shape of the square with css by selecting a div assigning properties of position, background color, width and height.
We select the div with id "square" and use the keydown function as a keyboard event when pressing a button that creates a function that will perform the following operation:
To move the square use the keys w, a, s, z.
Interesting Articles