.animate()
JQ Home <<
Effects <<
.animate()
Custom animation.
Description
The .animate()
method is used to perform a custom animation for a set of CSS properties.
- The
.animate()
method does not make hidden elements visible as part of the effect. The animation will still run, but the element will remain hidden. - When hiding elements the
display
property of the elements to be hidden is stored in the jQuery cache, so if the element is later made visible, thedisplay
property is restored to its initial value. - When showing elements the
display
property of the element to be shown is restored to its initial value. If using!important
in your styles, it is necessary to override the style using.css('display', 'block !important')
for the.show()
method to function correctly - When the
duration
,easing
orcallback
parameters are used, the.toggle()
method becomes an animation method. - There is also a mouse event named .toggle() and the method that is fired depends on the set of arguments passed.
Syntax
Signature | Description |
---|---|
.animate( properties [, duration] | Perform a custom animation for a set of CSS properties optionally providing a duration, and/or an easing and/or a callback function. |
.animate( properties, options ) | Perform a custom animation for a set of CSS properties optionally providing a map of additional options. |
Parameters
Parameter | Description | Type |
---|---|---|
properties | A plain JavaScript object of CSS style properties that the animation will move toward.
|
PlainObject |
duration | A string or number determining the time the animation will run for. default: 400
| String orNumber |
easing | Specify the speed at which the animation progresses at different points within the animation. default: swing
| String |
complete | A function that fires once the animation is complete.
| Function |
options | A map of additional options to pass to the method, supported keys being:
Promise object, allow us to report animation progression and notification of animation completion
were added in jQuery 1.8 and are listed below:
|
PlainObject String orNumber String
PlainObject Function
Boolean orString
Function Function
Function Function
Function |
Return
A jQuery
object.
.animate( properties [, duration]
[, easing] [, complete] )
Example
Effects << Top
[, easing] [, complete] )
Perform a custom animation for a set of CSS properties optionally providing a duration, and/or an easing and/or a callback function.
In the examples below we are using different properties/styles/toggles. Press the buttons to see these animations
$(function(){
$('#btn21').on('click', function() {
$('#pie10').animate({
opacity: 0.5,
left: '+=20',
height: 'toggle'
}, 1200, 'swing'
);
});
$('#btn22').on('click', function() {
$('#pie11').animate({
opacity: 0.3,
top: '+=20',
width: 'toggle'
}, 1200, 'linear'
);
});
$('#btn23').on('click', function() {
$('#pie12').animate({
opacity: 0.75,
width: 'toggle',
height: 'toggle',
}, 1200, 'swing'
);
});
});
.animate( properties, options )
Example
Effects << Top
Perform a custom animation for a set of CSS properties optionally providing a map of additional options.
In the example below we are using toggle properties with some options.
$(function(){
$('#btn24').on('click', function() {
$('#div1 .curry11').first().animate({
width: 'toggle',
height: 'toggle'
}, {
duration: 1200,
specialEasing: {
width: 'linear'
},
complete: function() {
// using 'callee' so we don't have to name the function
$(this).next().toggle(400, arguments.callee);
}
});
});
});
Related Tutorials
jQuery Intermediate Tutorials - Lesson 6 - Basic & Custom Effects