1
3

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 5 years have passed since last update.

【バグ】ChromeでCSSアニメーションがうまく描画されない

Posted at

やりたいこと

裏表に文字が書かれたカード(div#card)に回転するアニメーションを付ける。
fixed.gif

症状

裏面(div.back)がうまく描画されない。
bug.gif

発生条件

backface-visibility: hiddenを指定している要素に対して回転アニメーションをつけると発生。

Blinkのバグと思われる。

  • Chrome 76.0.3809.132

  • Opera 63.0.3368.66
    では発生。

  • Firefox 68.0.2
    では発生せず。

対策

@keyframes内でz-index: autoなどを明示的に指定することで再描画を促す。

CSS
@keyframes rotate {
  from {
    z-index: auto;  /* これを追加 */
    -webkit-transform: rotate(0);
    transform: rotateY(0);
  }
  to {
    -webkit-transform: rotate(360deg);
    transform: rotateY(360deg);
  }
}

サンプルコード

HTML/CSS
HTML
<div id="card">
  <div class="front">Front</div>
  <div class="back">Back</div>
</div>
CSS
# card {
  width: 300px;
  height: 100px;
  perspective: 1000px;
}

.front,
.back {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  color: white;
  font-size: 60px;
  text-align: center;
}

.front {
  background-color: teal;
  -webkit-animation: rotate 4s linear infinite;
  animation: rotate 4s linear infinite;
}

.back {
  background-color: orangered;
  -webkit-animation: rotate 4s linear -2s infinite;
  animation: rotate 4s linear -2s infinite;
}

@keyframes rotate {
  from {
    z-index: auto;  /* これを追加 */
    -webkit-transform: rotate(0);
    transform: rotateY(0);
  }
  to {
    -webkit-transform: rotate(360deg);
    transform: rotateY(360deg);
  }
}
1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?