.fadeIn()
Syntax
$(selector).fadeIn([speed,] [easing,] [callback]);
Parameters
duration (optional)
- A string or number determining how long the animation will run
callback (optional)
- A function to call once the animation is complete
Return value
The jQuery object, for chaining purposes.
Description
Display the matched elements by fading them to opaque.
The .fadeIn() method animates the opacity of the matched elements.
Durations are given in milliseconds; higher values indicate slower animations.
The 'fast' and 'slow' strings can be supplied to indicate durations of 200 and 600 milliseconds, respectively.
If supplied, the callback is fired once the animation is complete.
Examples
Fade in callback
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").fadeIn(1000, function () {
alert("done");
});
});
</script>
</head>
<body>
<body>
<div style="display:none;">Click me</div>
</body>
</html>
Fast fade in
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").fadeIn("fast");
});
</script>
</head>
<body>
<body>
<div style="display:none;">Click me</div>
</body>
</html>
Fade in controlled by milliseconds
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").fadeIn(2000);
});
</script>
</head>
<body>
<body>
<div style="display:none;">Click me</div>
</body>
</html>
Slow fade in
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").fadeIn("slow");
});
</script>
</head>
<body>
<body>
<div style="display:none;">Click me</div>
</body>
</html>
Header fade in and fade out
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("h1").css("opacity", 1).fadeIn(30).fadeOut(1000);
});
</script>
</head>
<body>
<body>
<div><h1>header 1</h1></div>
</body>
</html>
Cascade fade out animation
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#info").fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400).fadeOut(400).fadeIn(400);
});
</script>
</head>
<body>
<div style="" id="info">an animated info message</div>
</body>
</html>