.animate(…)
- … – miscellaneous parameters
- any parameter accepted by the original
.animate()
.
See jQuery API for .animate(…)
.
Usage pattern
Examples with classical usage of .animate()
Example #11: change the banner randomly in an interval loop
Given that you have a method which selects any element from the current jQuery set randomly,e.g. ,
then you can use that to build a banner rotator very easily.
In this example there are four different banners. Every 5 seconds another one fades in, randomly chosen.
As we don't want to wait for the animations finishing we use the original version of .fadeIn() and .fadeOut() here.
⇒Some banner text?
some more text here
Some other cool stuff?
this is other text
Even different text
this is new text
Attention!
cheaper, cheaper, cheaper…
Example #16: playing pong with divs
In this example we work with two different animation queues.
The horizontal animation for the ball uses the effects queue named 'myFX'. We have to start that queue manually using .dequeue('myFX').
The vertical animation uses the default queue which always starts on its own. It includes all three moving elements at once.
Because the two queues will be animated with different repeating intervals the ball doesn't always take the same path.
⇒Example #17: scheduling different elements' animations
Here we use an instant repeat-loop together with a sequential each-loop.
In each iteration step we wait until the element is completely shifted up using .animate({opacity:0,top:-50},$)
.
Then the next animation is queued with .animate({opacity:1,top:0})
, which shifts the element down again but without waiting.
The loop starts its next iteration, now using the next element.
So we have one element going up and another element going down simultaneously.
As you see the usage of $ as token in place of the animate callback handler decides about whether to wait for the animation to finish.
⇒Example #20: ruler with animation
This example shows how to create a ruler with an animated selection mark.
Each time the user clicks on one of the tick marks the button moves up to this mark. During its animation all underlying ticks get highlighted when the button flies by.
This is the complete code:
⇒