注意すべき重要な点の1つは、CSStransition
プロパティ自体が省略形であるということです-MDN WebDocsで述べられているように:
transition
CSSプロパティは、、、、およびの省略transition-property
形のtransition-duration
プロパティtransition-timing-function
ですtransition-delay
。
この省略形の理想的な使用法は、単一の遷移のさまざまな構成要素のプロパティを組み合わせることです。これを使用して複数のトランジションを組み合わせると、不格好になり始めます。
したがって、構成プロパティが異なる同じ要素に3つ以上のトランジションがある場合、省略形を使用する代わりに、それらを個別に記述する方が簡単になりますtransition
。例えば:
これは、1つの要素での複数の遷移の短縮バージョン(オプション1)です。
transition: transform 0.5s ease-in-out, box-shadow 0.2s ease-out, filter 0.1s ease-out, color 0.25s ease-in 0.2s;
ご覧のとおり、これは不格好になり、視覚化が少し難しくなります。
同じCSSを次のように適用できます(オプション2):
transition-property: transform, box-shadow, filter, color;
transition-duration: 0.5s, 0.2s, 0.2s, 0.25s;
transition-timing-function: ease-in-out, ease-out, ease-out, ease-in;
transition-delay: 0s, 0s, 0s, 0.2s
もちろん、最終的には、ソースコードの入力と保守の好みに依存します。しかし、私は個人的に2番目のオプションを好みます。
ヒント:
これを使用することの追加の利点は、Constituentプロパティの1つがすべての遷移で同じである場合、それを何度も言及する必要がないことです。たとえば、上記の例で、がすべての場合transition-duration
にsame(0.5s
)である場合は、次のように記述します。
transition-property: transform, box-shadow, filter, color;
transition-duration: 0.5s;
transition-timing-function: ease-in-out, ease-out, ease-out, ease-in;
transition-delay: 0s, 0s, 0s, 0.2s