jQueryのfadeToggle()メソッド

❮jQueryエフェクトメソッド

別のボックスのフェードインとフェードアウトを切り替えます。

$("button").click(function(){
  $("#div1").fadeToggle();
});

定義と使用法

およびfadeToggle()メソッドは、 fadeIn ()メソッドとfadeOut( )メソッドを切り替えます。

要素がフェードアウトされている場合、fadeToggle()は要素をフェードインします。

要素がフェードインされている場合、fadeToggle()はそれらをフェードアウトします。

:非表示の要素はまったく表示されません(ページのレイアウトには影響しなくなりました)。


構文

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

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

Possible values:

  • milliseconds
  • "slow"
  • "fast"
easing Optional. Specifies the speed of the element in different points of the effect. 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 fadeToggle() method is completed

To learn more about callback, please read our jQuery Callback chapter

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


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


の使用fadeToggle()メソッドの完了後にコールバックパラメーターを使用して関数を実行する方法。


❮jQueryエフェクトメソッド