業務備忘録

備忘録です

jqueryのshowメソッドについて

2023-07-06 23:23:44 | 日記
The matched elements will be revealed immediately, with no animation. This is roughly equivalent to calling .css( "display", "block" ), except that the display property is restored to whatever it was initially. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline.

https://api.jquery.com/show/

一致した?HTMLの要素はアニメーションなしで瞬時に表示される。大まかにいえばcssメソッドでdisplay:flexを適用した場合と等価であるが、非表示にされた要素のdisplayプロパティに値が指定されていれば、表示されたときにはdisplay:blockではなくdisplay:[初期値]として表示される。

とのこと。

showメソッドにはオプションの指定が可能だが、アニメーションに関するものであるようだ。

duration:A string or number determining how long the animation will run.

jquery 3.0以前とはshow/hideメソッドの仕様が変更されているらしく、 3.0以降はhideでdisplay:noneを追加し、showでdisplay:noneを削除するという操作になったようだ。であればdisplayに初期値を設定していればそれが適用されるのも当然ということなのだろう。