Easy Tutorial
❮ Event Keydown Eff Finish ❯

jQuery Effects - Fade In/Out


With jQuery, you can achieve fade in and fade out effects for elements.

Click to show the Fade In/Out panel

Since time is precious, we provide quick and convenient learning methods.

At tutorialpro.org, you can learn the knowledge you need.


Examples

jQuery fadeIn()

jQuery fadeOut()

jQuery fadeToggle()

jQuery fadeTo()


jQuery Fading Methods

With jQuery, you can achieve fade in and fade out effects for elements.

jQuery has the following four fade methods:


jQuery fadeIn() Method

The jQuery fadeIn() method is used to fade in hidden elements.

Syntax:

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 a 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);
});

jQuery fadeOut() Method

The jQuery fadeOut() method is used to fade out visible elements.

Syntax:

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 a 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);
});

jQuery fadeToggle() Method

The jQuery fadeToggle() method toggles between the fadeIn() and fadeOut() methods.

If the elements are faded out, fadeToggle() adds a fade in effect to the elements.

If the elements are faded in, fadeToggle() adds a fade out effect to the elements.

Syntax:

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 a 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);
});

jQuery fadeTo() Method

The jQuery fadeTo() method allows fading to a given opacity (value between 0 and 1).

Syntax:

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 fade in/out effect to a given opacity (value between 0 and 1).

The optional callback parameter is the name of a function to be executed after the fading 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);
});
❮ Event Keydown Eff Finish ❯