fadeToggle() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:fadeToggle

Description

The fadeToggle() method toggles between the fadeIn() and fadeOut() methods.

Syntax

$(selector).fadeToggle(speed,easing,callback);
Parameter Require Description Value
speed Optional. speed of the fading effect.Default value is 400 milliseconds Possible values: milliseconds "slow" "fast"
easingOptional. speed of the element in different points of the effect.Default value is "swing"
callback Optional. A function to be executed after the fadeToggle() method is completed a function

Possible easing values:

  • "swing" - slower at the beginning/end, but faster in the middle
  • "linear" - in a constant speed

The following code shows how to Toggle between fading in and fading out different boxes:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").fadeToggle("slow", function(){
            console.log("The fadeToggle effect is finished!");
        });//  w w w .  ja v a2  s  .c  o  m
    });
});
</script>
</head>
<body>

<button>Click me</button>

<p>This is a paragraph.</p>

</body>
</html>

Related Tutorials