jQuery fadeIn() can be applied on HTML element to generate a fading effect. Usually, the initial state of the HTML element is hidden, so that when fadeIn effect is applied, the display attribute of element is changed to visible with the transition effect as fading.
In this tutorial, you will learn about jQuery fadeIn() method, its syntax and usage, with examples.
Syntax – jQuery fadeIn()
The syntax to use jQuery fadeIn() method is as shown in the following.
1. jQuery fadeIn – Default
To fade in a selected HTML Element with default timing,
2. jQuery fadeIn – slow/fast
You can also provide a “slow” or “fast” argument to the fadeIn() method to make the fading process slow or fast respectively.
3. jQuery fadeIn – Time in milliseconds
To control the timing precisely, you can provide time in milliseconds as the argument to jQuery fadeIn() method
$("htmlElement").fadeIn(4000); // for 4000 milliseconds
Examples – jQuery fadeIn()
Following examples help you understand the usage of jQuery fadeIn() method :
1. Example – Basic jQuery fadeIn()
Following is a basic example to demonstrate the usage to jQuery fadeIn() method to get fading effect of HTML Element(s).
2. Example – jQuery fadeIn(“slow”), fadeIn(“fast”)
“slow” and “fast” are the two quick options that control the speed of fading. The words slow and fast are self explanatory for the speed of fading.
3. Example – jQuery fadeIn(time_in_milliseconds)
To control the speed of fading, jQuery fadeIn() method could be passed with milliseconds as argument. Following example illustrates the same. 1000ms = 1sec, hence $(“#div1”) fades-in in 1sec while $(“#div1”) fades-in in 4000ms = 4sec.
4. Example – jQuery fadeIn() with Callback function
Callback function is an optional second argument. The callback function is called when the fading in effect is completed. In the following example, we have provided a callback function with alert statement inside the body. You can provide your own statements inside the callback function.