Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery fadeToggle() method

jQuery fadeToggle() method

jQuery effects methods jQuery effects methods

Example

Toggle between fading in and fading out different boxes:

$("button").click(function(){

$("#div1").fadeToggle();

});

Try it »


Definition and Usage

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

If elements are hidden (faded out), fadeToggle() shows them with a fade-in effect.

If elements are shown (faded in), fadeToggle() hides them with a fade-out effect.

**Note:** Hidden elements will not be fully displayed (they no longer affect the page's layout).


Syntax

$(

selector

).fadeToggle(

speed,easing,callback

)

Parameters Description
speed Optional. Specifies the speed of the fading effect.

Possible values:

  • Millisecond
  • "slow"
  • "fast"
  • | | *easing* | Optional. Specifies the speed of the element at different points in the animation. The default is "swing".

    Possible values:

    **Tip:** More easing functions are available in extension plugins. | | *callback* | Optional. A function to be executed after the fadeToggle() method finishes.
     如需学习更多有关 callback 的内容,请访问我们的 [jQuery Callback](jquery-callback.html) 这一章。 |
    
    

    More examples

    fadeToggle() - Using the speed parameter
    How to use the speed parameter to specify the speed of the fading effect.

    fadeToggle() - Using the callback parameter
    How to use the callback parameter to execute a function after the fadeToggle() method completes.


    jQuery effects methods jQuery effects methods