How to fade an element in and out using jQuery
fadeIn
The jQuery fadeIn() method is used to fade in a hidden element.
Syntax
$(selector).fadeIn(speed, callback);
-
speedis an optional parameter used to specify the duration of any applied effect. It can take on values such as “slow”, “fast”, or any other specified integer value of speed (in milliseconds). -
callbackis another optional parameter that refers to a function that a user may want to execute at the end of fading.
fadeOut
The jQuery fadeOut() method is used to fade out a visible element.
Syntax
$(selector).fadeOut(speed, callback);
-
speedis an optional parameter used to specify the duration of any applied effect. It can take on values such as “slow”, “fast”, or any other specified integer value of speed (in milliseconds). -
callbackis another optional parameter that refers to a function a user may want to execute at the end of fading.
Example
Let’s visualize the workings of fadeIn() and fadeOut():
Free Resources