jQuery Effects - Fading
With jQuery, you can achieve fading effects on elements.
Click to Show Fade In / Fade Out Panel
Because time is precious, we provide a quick and convenient way to learn.
At Runoob Tutorial, you can learn what you need.
Example
jQuery fadeIn()
Demonstrates the jQuery fadeIn() method.
jQuery fadeOut()
Demonstrates the jQuery fadeOut() method.
jQuery fadeToggle()
Demonstrates the jQuery fadeToggle() method.
jQuery fadeTo()
Demonstrates the jQuery fadeTo() method.
jQuery Fading Methods
With jQuery, you can achieve fading effects on elements.
jQuery has the following four fade methods:
- fadeIn()
- fadeOut()
- fadeToggle()
- fadeTo()
jQuery fadeIn() method
jQuery fadeIn() is used to fade in hidden elements.
Syntax:
$(
selector
).fadeIn(
speed,callback
);
The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.
The optional callback parameter is the name of the function to be executed after the fading completes.
The following example demonstrates the fadeIn() method with different parameters:
Example
$
(
"
button
"
)
.
click
(
function
(
)
{
$
(
"
#div1
"
)
.
fadeIn
(
)
; $
(
"
#div2
"
)
.
fadeIn
(
"
slow
"
)
; $
(
"
#div3
"
)
.
fadeIn
(
3000
)
;
}
)
;
Try it »
jQuery fadeOut() Method
The jQuery fadeOut() method is used to fade out visible elements.
Syntax:
$(
selector
).fadeOut(
speed,callback
);
The optional speed parameter specifies the duration of the effect. It can take the values "slow", "fast" or milliseconds.
The optional callback parameter is the name of the function to be executed after the fading completes.
The following example demonstrates the fadeOut() method with different parameters:
Example
$
(
"
button
"
)
.
click
(
function
(
)
{
$
(
"
#div1
"
)
.
fadeOut
(
)
; $
(
"
#div2
"
)
.
fadeOut
(
"
slow
"
)
; $
(
"
#div3
"
)
.
fadeOut
(
3000
)
;
}
)
;
Try it »
jQuery fadeToggle() method
The jQuery fadeToggle() method can switch between the fadeIn() and fadeOut() methods.
If the element is faded out, fadeToggle() adds a fade-in effect to it.
If the element is faded in, fadeToggle() adds a fade-out effect to it.
Syntax:
$(
selector
).fadeToggle(
speed,callback
);
The optional speed parameter specifies the duration of the effect. It can take the values "slow", "fast" or milliseconds.
The optional callback parameter is the name of the function to be executed after the fading completes.
The following example demonstrates the fadeToggle() method with different parameters:
Example
$
(
"
button
"
)
.
click
(
function
(
)
{
$
(
"
#div1
"
)
.
fadeToggle
(
)
; $
(
"
#div2
"
)
.
fadeToggle
(
"
slow
"
)
; $
(
"
#div3
"
)
.
fadeToggle
(
3000
)
;
}
)
;
Try it »
jQuery fadeTo() Method
The jQuery fadeTo() method allows fading to a given opacity (a value between 0 and 1).
Syntax:
$(
selector
).fadeTo(
speed,opacity,callback
);
The required speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.
The required opacity parameter in the fadeTo() method sets the fading effect to a given opacity (a value between 0 and 1).
The optional callback parameter is the name of the function to be executed after the function completes.
The following example demonstrates the fadeTo() method with different parameters:
Example
$
(
"
button
"
)
.
click
(
function
(
)
{
$
(
"
#div1
"
)
.
fadeTo
(
"
slow
"
,
0.15
)
; $
(
"
#div2
"
)
.
fadeTo
(
"
slow
"
,
0.4
)
; $
(
"
#div3
"
)
.
fadeTo
(
"
slow
"
,
0.7
)
;
}
)
;
Try it »