.fadeOut()
Syntax and Description
$(selector).fadeOut([speed,] [easing,] [callback]);
Hide the matched elements by fading them to transparent.
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.
The .fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the display style property is set to none.
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.
Fade out button
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!-- w w w .j a v a 2 s. com-->
$("button").click(function () {
$(this).fadeOut();
});
});
</script>
</head>
<body>
<body>
<div>Click me<button>button</button></div>
</body>
</html>
The code above generates the following result.
Fast fade out
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from w w w .j av a2 s . c om-->
$("button").click(function () {
$(this).fadeOut("fast");
});
});
</script>
</head>
<body>
<body>
<div>Click me<button>button</button></div>
</body>
</html>
The code above generates the following result.
Fade out in milliseconds
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from www . j av a2s.c om-->
$("button").click(function () {
$(this).fadeOut(2000);
});
});
</script>
</head>
<body>
<body>
<div>Click me<button>button</button></div>
</body>
</html>
The code above generates the following result.
Fade out one second
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!-- www .j a v a 2 s.co m-->
$("div").text("selected").show().fadeOut(1000);
});
</script>
</head>
<body>
<body>
<div></div>
</body>
</html>
The code above generates the following result.
Slow fade out
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!-- www . j av a2 s . c om-->
$("button").click(function () {
$(this).fadeOut("slow");
});
});
</script>
</head>
<body>
<body>
<div>Click me<button>button</button></div>
</body>
</html>
The code above generates the following result.
Paragraphs to fade out
Animates all paragraphs to fade out, completing the animation within 600 milliseconds.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from ww w . ja va 2s. c o m-->
$("p").click(function () {
$("p").fadeOut("slow");
});
});
</script>
</head>
<body>
<body>
<p>fade away. java2s.com</p>
</body>
</html>
The code above generates the following result.