English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery effect slideToggle() method

jQuery Effect Methods

The slideToggle() method inslideUp()andslideDown()Switch between methods.

This method checks the visibility of the selected element:

  • If the element is initially displayed, it will be hidden

  • If the element is initially hidden, it will be displayed

Note:Hidden elements will no longer affect the page layout.

Syntax:

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

Example

Toggle between moving up and down on all <p> elements when the button is clicked:

$("button").click(function() {
  $("p").slideToggle();
});
Test and see‹/›

UsedurationParameters:

$("button").click(function() {
  $("p").slideToggle();1500);
});
Test and see‹/›

UsecallbackParameters:

$("button").click(function() {
  $("div").slideToggle();1500, function() {
    alert("Slide toggle effect completed!!!");
  });
});
Test and see‹/›

Use slow duration and linear easing to toggle all " .panel":

$("#my-Div").click(function(){
  $(".panel").slideToggle("slow", "linear");
});
Test and see‹/›

Parameter Value

ParameterDescription
duration(Optional) Determines how long the sliding effect will last. The preset value is400 milliseconds

Possible values:

  • milliseconds (e.g.,100,500,2(e.g., 000)

  • "fast"

  • "slow"

easing(Optional) A string that specifies the speed of the element at different points of the animation. The default value is "swing"

Possible values:

  • "swing"-At the beginning/Move slower at the end and faster in the middle

  • "linear"-Move at a constant speed

callback(Optional) This function is called once the slideToggle() method is completed, for each selected element

jQuery Effect Methods