0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

animation-delay と var() に起因する不具合

0
Posted at

以下の条件が揃うと、Chrome において意図しないアニメーション挙動が発生することを確認しました。

  • animation-delay を使用している
  • keyframes 内で var() を使用している
  • CSS 変数の値を非同期に変更している (例: React の useEffect で DOM 要素を取得後に変数を設定する)

実例

以下の CodePen を Firefox と Chrome で開き、挙動を比較してみてください。
本来は Firefox のように、赤い正方形が静止している状態が期待される動作ですが、Chrome では正方形が動いてしまっています。

See the Pen animation-delay-var-bug by inonote (@inonote) on CodePen.

回避策

CSS だけでトリッキーなことをせずに Web Animations API を使いましょう。

おまけ

興味深いことに、Chrome の開発者ツールで要素を調査すると、描画上は (意図せず) 動いているのにもかかわらず本来あるべき場所にハイライトが表示されます。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?