jQuery in Action
Creating custom animations
145
5.2.4 Stopping animations
We may have a reason now and again to stop an animation once it has started.
This could be because a user event dictates that something else should occur or
because we want to start a completely new animation. The
This could be because a user event dictates that something else should occur or
because we want to start a completely new animation. The
stop()
command will
achieve this for us:
Note that any changes that have already taken place for any animated elements
will remain in effect. If we want to restore the elements to their original state, it's
our responsibility to put the
will remain in effect. If we want to restore the elements to their original state, it's
our responsibility to put the
CSS
values back to their starting values using the
css()
method or similar commands.
Now that we've seen the effects built into core jQuery, let's investigate writing
our own!
5.3 Creating custom animations
The number of core effects supplied with jQuery is purposefully kept small (in
order to keep jQuery's core footprint to a minimum) with the expectation that
plugins are available to add more animations at the page author's discretion. It's
also a simple matter to write our own animations.
order to keep jQuery's core footprint to a minimum) with the expectation that
plugins are available to add more animations at the page author's discretion. It's
also a simple matter to write our own animations.
jQuery publishes the
animate()
wrapper method that allows us to apply our
own custom animated effects to the elements of the wrapped set. Let's take a look
at its syntax.
at its syntax.
Command syntax: stop
stop()
Halts all animations that may be currently in progress for the elements in the matched set
Parameters
none
Returns
The wrapped set
The wrapped set