Example of fadeOut of method usage in jQuery

  • 2020-05-09 18:08:27
  • OfStack

This article illustrates the use of the fadeOut() method in jQuery as an example. Share with you for your reference. The specific analysis is as follows:

This method fades out all matched elements through a change in opacity, and optionally triggers a callback function after the animation is complete.

Usage of the fadeOut() method:

This method specifies the duration of the animation effect. Such as:

$("div").fadeOut(5000)

The above code specifies that div's fade-out effect can be completed in 5000 milliseconds (5 seconds).
This method can also trigger a callback function after the animation is complete. Such as:

$("div").fadeOut(5000,function(){alert(' Animation finished! ')})

The above code can trigger the callback function after the animation is completed, and a prompt box will pop up.
Example code:


<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="author" content="//www.ofstack.com/" />
<title>fadeOut() function - The home of the script </title>
<style type="text/css">
div{
  background:#060;
  width:300px;
  height:300px;
  color:red
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#up").click(function(){
    $("div").fadeOut(5000,function(){alert(' Animation finished! ')});
  })
})
</script>
</head>
<body>
  <div></div>
  <button id="up"> Click to view </button>
</body>
</html>

The above code clicks the button to slowly set div to the transparent effect, and when it is fully transparent, then specifies the callback function.

I hope this article has been helpful to your jQuery programming.


Related articles: