File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 61180
    
  66

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: 61180
    
  66

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions about Javascript animation.