jQuery fadeIn() Method
jQuery fadeIn() Method
The jQuery fadeIn()
method will display the matched elements by fading them to opaque.
This method is often used with jQuery fadeOut() method.
Note: Using fadeIn()
method, the hidden elements will not be displayed at all.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>jQuery fadeIn() Method</h1>
<button id="myFadeOut">Fade Out</button>
<button id="myFadeIn">Fade In</button>
<script>
$(document).ready(function(){
$("#myFadeOut").click(function(){
$("p").fadeOut();
});
$("#myFadeIn").click(function(){
$("p").fadeIn();
});
});
</script>
</body>
</html>
Syntax
$(selector).fadeIn(speed, easing, callback);
Parameter Values
Value | Type | Explanation |
---|
speed | Optional | Specifies the speed of the fading effect. Default value is 400 milliseconds. Possible values are |
easing | Optional | Specifies the easing function to use for the transition. Default value is "swing" Possible values are
|
callback | Optional | Specifies a function to be called once the animation is completed. |
fadeIn() with Speed
In the following example, we will specify the speed of the fading effect for fadeIn()
method to 2000ms (2 seconds).
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>jQuery fadeIn() Method</h1>
<button id="myFadeOut">Fade Out</button>
<button id="myFadeIn">Fade In</button>
<script>
$(document).ready(function(){
$("#myFadeOut").click(function(){
$("p").fadeOut();
});
$("#myFadeIn").click(function(){
$("p").fadeIn(2000);
});
});
</script>
</body>
</html>
fadeIn() with Easing
In the following example, we will specify the easing function for fadeIn()
method to linear.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>jQuery fadeIn() Method</h1>
<button id="myFadeOut">Fade Out</button>
<button id="myFadeIn">Fade In</button>
<script>
$(document).ready(function(){
$("#myFadeOut").click(function(){
$("p").fadeOut();
});
$("#myFadeIn").click(function(){
$("p").fadeIn(2000, "linear");
});
});
</script>
</body>
</html>
fadeIn() with Callback
In the following example, we will call a function (myFunction) once the fading effect for fadeIn()
method is finished.
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>jQuery fadeIn() Method</h1>
<button id="myFadeOut">Fade Out</button>
<button id="myFadeIn">Fade In</button>
<script>
$(document).ready(function(){
$("#myFadeOut").click(function(){
$("p").fadeOut();
});
$("#myFadeIn").click(function(){
$("p").fadeIn(2000, "linear", myFunction);
});
});
function myFunction(){
alert("fadeIn is completed");
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 99.5% of jQuery Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in jQuery.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.
Share this Page
Meet the Author