jQuery | Effect fadeOut() Method

The fadeOut()Method in jQuery is used to change the level of opacity for selected element from visible to hidden. By using this method, the fadded element will not occupy any space.

Syntax:

$(selector).fadeOut( speed, easing, callback )

Parameters: This method accepts three parameters as mentioned above and described below:



  • Speed: It is an optional parameter and used to specify the speed of the fading effect. The default value of speed is 400 millisecond. The possible value of speed are:
    • milliseconds
    • “slow”
    • “fast”
  • Easing: It is an optional parameter and used to specify the speed of element to different points of animation. The default value of easing is “swing”. The possible value of easing are:
    • “swing”
    • “linear”
  • callback: It is optional parameter. The callback function is executed after fadeOut() method is completed.

Example 1: This example display fadeIn and fadeOut effect.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head
    <title>
        jQuery | fadeOut() Method
    </title>
  
    <script src=
    </script>
</head
  
<body style = "text-align:center;">  
  
    <h1 style = "color:green;" >  
        GeeksForGeeks
    </h1>  
      
    <h2>jQuery | fadeOut() Method</h2>
  
    <button class="btn1">Fade out</button>
  
    <button class="btn2">Fade in</button>
      
    <!-- Script to display fadeIn and fadeOut effect -->
    <script>
        $(document).ready(function(){
            $(".btn1").click(function(){
                $("h2").fadeOut()
            });
              
            $(".btn2").click(function(){
                $("h2").fadeIn();
            });
        });
    </script>
</body>
  
</html>  

chevron_right


Output

Example 2: This example create fadeIn and fadeOut effect and set its speed. The given speed in terms of milliseconds.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head
    <title>
        jQuery | fadeOut() Method
    </title>
  
    <script src=
    </script>
</head
  
<body style = "text-align:center;">  
  
    <h1 style = "color:green;" >  
        GeeksForGeeks
    </h1>  
      
    <h2>jQuery | fadeOut() Method</h2>
  
    <button class="btn1">Fade out</button>
  
    <button class="btn2">Fade in</button>
  
    <script>
        $(document).ready(function(){
            $(".btn1").click(function(){
                $("h2").fadeOut(1000);
            });
              
            $(".btn2").click(function(){
                $("h2").fadeIn(1000);
            });
        });
    </script>
</body>
  
</html>  

chevron_right


Output:
After Click on fade out button

After Click on fade in button

Example 3: Create fadeIn and fadeOut effect with alert message.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head
    <title>
        jQuery | fadeOut() Method
    </title>
  
    <script src=
    </script>
</head
  
<body style = "text-align:center;">  
  
    <h1 style = "color:green;" >  
        GeeksForGeeks
    </h1>  
      
    <h2>jQuery | fadeOut() Method</h2>
  
    <button class="btn1">Fade out</button>
  
    <button class="btn2">Fade in</button>
      
    <!-- Script to create fadeIn and fadeOut effect -->
    <script>
        $(document).ready(function() {
            $(".btn1").click(function() {
                $("h2").fadeOut(1000, function() {
                    alert("fadeOut() method is finished!");
                });
            });
              
            $(".btn2").click(function() {
                $("h2").fadeIn(1000, function(){
                    alert("fadeIn() method is finished!");
                });
            });
        });
    </script>
</body>
  
</html>  

chevron_right


Output:
After Click on fade out button

After Click on fade in button



My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.