Overclock.net banner

1 - 3 of 3 Posts

·
Registered
Joined
·
193 Posts
Discussion Starter #1
My programming goes as far as C, so not far. I'm trying to help a friend with her Javascript and figured I could get some help here. Heres what she gave me.

var pos=50
setInterval ("move()",50)
function move()
{
if (pos>max||pos<min)
{
...do something
}
myElement.style.top=pos;
}

I assume the ball is supposed to bounce and come to a rest, although she never said it came to rest. She said it keeps bouncing. Anyone give me any help?
 

·
Premium Member
Joined
·
798 Posts
What you can do is create a direction variable that could add or subtract from the position of the ball ( pos+=direction; ). To make is simple, make this variable equal to 1 or -1. If a bounce occurs ( if (pos>max||pos<min) ) multiply your direction value by -1 switching the polarity. That should get you started

edit: forgot the semicolon
 
1 - 3 of 3 Posts
Top