jQuery slideToggle()Methods

jQuery 效果方法jQuery Effects Methods

Examples

Toggle between slideUp() and slideDown() on all <p> elements:

$("button").click(function(){
$("p").slideToggle();
});

Try it Yourself »

Definition and Usage

The slideToggle() method performs on the selected elementsslideUp()andslideDown()the toggle between.

This method checks the visible state of the selected elements. If an element is hidden, slideDown() is run; if an element is visible, slideUp() is run - this creates a toggle effect.

Syntax

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

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

Possible values:

  • Milliseconds
  • "slow"
  • "fast"
easing Optional. Specifies the speed of the element at different points in the animation. Default value is "swing".

Possible values:

  • "swing" - moves slowly at the beginning/end, fast in the middle
  • "linear" - moves at a constant speed
Tip:More easing functions are available in extension plugins.
callback Optional. A function to execute after the slideToggle() method has finished executing.

To learn more about callback, please visit ourjQuery Callbackthis chapter.



实例

More Examples

slideToggle() - Use the speed parameter
How to use the speed parameter to specify the speed of the sliding effect.

slideToggle() - Use the callback parameter
How to use the callback parameter to toggle between slideUp() and slideDown().


jQuery 效果方法jQuery Effects Methods

Other Extensions