jQuery slideToggle()メソッド

❮jQueryエフェクトメソッド

すべての<p>要素のslideUp()とslideDown()を切り替えます。

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

定義と使用法

slideToggle()メソッドは、選択した要素のslideUp()slideDown()を切り替えます。

このメソッドは、選択された要素の可視性をチェックします。スライドダウン()は、要素が非表示の場合に実行されます。スライドアップ()は、要素が表示されている場合に実行されます-これにより、トグル効果が作成されます。


構文

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

Parameter Description
speed Optional. Specifies the speed of the slide effect. Default value is 400 milliseconds

Possible values:

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

Possible values:

  • "swing" - moves slower at the beginning/end, but faster in the middle
  • "linear" - moves in a constant speed
Tip: More easing functions are available in external plugins
callback Optional. A function to be executed after the slideToggle() method is completed

To learn more about callback, visit our jQuery Callback chapter


自分で試してみてください-例


使用速度パラメーターを使用して、スライド効果の速度を指定する方法。


の使用slideUp()とslideDown()を切り替えるときにコールバックパラメーターを使用する方法。


❮jQueryエフェクトメソッド