This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Questions about Javascript animation. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Questions about Javascript animation." Watch "Questions about Javascript animation." New topic
Author

Questions about Javascript animation.

pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

Hi,

Just reading great book "Secrets of JavaScript Ninja". While learning closures. I thought of creating an animation. Please see it here animation.

I have two questions. Is there any way I can find out when ball reach the right end so that I can start from left again?
How to make it really smooth. Right now the transition is not smooth.

Let me know if I am doing something wrong.

Pawan Chopra
SCJP - DuMmIeS mInD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Making the animation smoother is a matter of taking smaller steps. Right now you are moving the ball in large steps.

Figuring out how to keep the ball within a bounding box is just a matter of math.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

Thanks Bear,

Seems difficult. But will try to do it.

pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

Done!!! Ninja Rocks . Thanks again.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Well done.

Now here's a challenge. Refactor the code, using closures, to have two balls animated at the same time with no extra variables.
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

Don't write such great books Bear...people can't sleep because of you! Two Balls
 
Consider Paul's rocket mass heater.
 
subject: Questions about Javascript animation.
 
Similar Threads
Making own Generic class
Object reference..........
horizontal scrolling
smoothing fonts
Creating Java applet