Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Questions about Javascript animation.

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,

Seems difficult. But will try to do it.

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done!!! Ninja Rocks . Thanks again.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 417
jQuery Mac Objective C
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't write such great books Bear...people can't sleep because of you! Two Balls
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic