.fadeToggle()
S2C Home « Effects « .fadeToggle()
Fading elements in and out.
Description
The .fadeToggle()
method is used to animate the opacity of the matched set to hide or show it.
Syntax
Signature | Description |
---|---|
.fadeToggle( [duration] [, easing] [, callback] ) | Animate the opacity of the matched set to hide or show it, optionally providing a duration and/or an easing and/or a callback function. |
Parameters
Parameter | Description | Type |
---|---|---|
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 |
callback | A function that fires once the animation is complete.
|
Function |
Return
A jQuery
object.
.fadeToggle( [duration] [,easing] [,callback] )
ExamplesTop
Animate the opacity of the matched set to hide or show it, optionally providing a duration and/or an easing and/or a callback function.
- When used in its basic form with no parameters or incorrect parameters the
.fadeToggle()
method defaults to fading in the element(s) with aduration
of 400 milliseconds which is the default.
In the example below when the first button is pressed we fade in or out the first image and it defaults to a fade in time of 400 milliseconds.
When the second button is pressed we use 'swing' easing to animate the picture as we fade it in or out.
When the third button is pressed we use a callback to alert when the image is faded in or out.
When the fourth button is pressed we use a duration, easing and a callback to fade in or out the last 3 images to their specified values.
$(function(){
$('#btn9').on('click', function() {
$('#curry3').fadeToggle();
});
$('#btn10').on('click', function() {
$('#pie7').fadeToggle('swing');
});
$('#btn11').on('click', function() {
$('#pie8').fadeToggle(function() {
alert('Animation finished.');
});
});
$('#btn12').on('click', function() {
$('.pie9').first().fadeToggle('slow', 'swing', function() {
// using 'callee' so we don't have to name the function
$(this).next().fadeToggle(1200, arguments.callee);
});
});
});
Related Tutorials
jQuery Intermediate Tutorials - Lesson 7 - Fading & Sliding Effects