When you press space div moves up

74 views Asked by At

I'm trying to do a tricky thing in Javascript, but it's not going well. Basically it's like: I have 2 balls(divs), one of them is on top: 100px and the other ball is on top 500px ( not actual values, just random ones ), and what I want to achieve is, when I press Space, the ball that is on top 500px, goes up to the top: 100px, and the other one does the opposite ( goes from top: 100px, to top: 500px, but with a cycle condition, like having speed, like a "for" that gives + 2px (or more) to the div until she reaches top: 500px, and vice versa.

I hope you understand what I'm trying to make here, a hand would be really appreciated.

1

There are 1 answers

0
Luka Krajnc On

First you want to look up for events.

Events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events. Found here.

Next thing you want to learn about is how to manipulate with DOM objects. You can learn more about it here.

When you will know more about those two things, you will be ready to solve this problem, that you are asking this community to do it instead of you.