Perform a custom animation of a set of CSS properties. Also includes shorthand methods for fading and sliding.
$('#box').animate({
opacity: 0.5,
marginLeft: '50px',
width: 200
}, {
duration: 600,
easing: 'ease-out',
after: () => console.log('Done')
});
<!-- After 600ms -->
<div id="box" style="opacity: 0.5; margin-left: 50px; width: 200px;"></div>
$('.panel').animate({ height: '0px' }, {
duration: 400,
easing: 'linear',
after: function() {
$(this).hide();
}
});
<!-- Step 1: Animates height to 0 -->
<!-- Step 2: Callback runs, setting display: none -->
<div class="panel" style="height: 0px; display: none;"></div>
$('#msg').fadeIn(400);
$('#menu').slideUp(200);
<div id="msg" style="display: block; opacity: 1;">...</div>
<div id="menu" style="display: none; height: 0px;">...</div>
| Parameter | Type | Description |
|---|---|---|
| properties | object | An object of CSS properties and values that the animation will move toward. Numeric values are treated as pixels unless specified otherwise. |
| settings | object | Optional. An object of settings to configure the animation.
|
Applies to: .fadeIn(), .fadeOut(), .fadeToggle(), .slideDown(), .slideUp(), .slideToggle().
| Parameter | Type | Description |
|---|---|---|
| duration | number | string | Optional. Duration in milliseconds or a preset ('fast', 'slow'). Default: 400. |
| callback | function | Optional. A function to call once the animation completes. |
Returns: The original SR object for chaining.