动画结束时 Internet Explorer 中不显示背景图像

Background Image not showing in Internet Explorer at the end of an animation

我已经尝试了一些这方面的东西,比如将 svg 换成 png,我盯着我的格式看,看不出有什么问题,我什么都想不出来。我想知道 CSS 动画是否会以某种方式干扰它?

这是 website 在其他浏览器中的效果,在 Internet Explorer 11 上,圆圈在动画结束时仍然是黄色圆圈。

#rosette {
  z-index: 99;
  position: absolute;
  background-color: crimson;
  height: 100vh;
  width: 100vw;
  animation: rosette-anim 5s;
  animation-fill-mode: forwards;
  content: "";
  transform-style: preserve-3d;
  background: rgb(51, 55, 56);
  top: 0px;
  right: 0px;
  transform: rotateY(0.5turn);
}

@keyframes rosette-anim {
  95% {
    position: absolute;
    background: rgb(51, 55, 56);
    height: 137px;
    width: 142px;
    border-radius: 70px;
    transform: rotateY(2turn);
    top: 4px;
    right: 20px;
  }
  100% {
    position: absolute;
    height: 137px;
    width: 142px;
    border-radius: 70px;
    transform: rotateY(3turn);
    background: rgb(164, 132, 60) url('https://www.pottertour.co.uk/imagesAwards/lux-life-award-transparent-min.svg');
    background-size: 139px 100px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 1;
    top: 4px;
    right: 26px;
  }
}
<div id="rosette"></div>

我为背景图像使用了 ::before 伪元素,我为动画 ::before 元素编写了另一个关键帧动画。这适用于 IE11。

#rosette {
  z-index: 99;
  position: absolute;
  background-color: crimson;
  height: 100vh;
  width: 100vw;
  animation: rosette-anim 5s;
  animation-fill-mode: forwards;
  transform-style: preserve-3d;
  background: rgb(51, 55, 56);
  top: 0px;
  right: 0px;
  transform: rotateY(0.5turn);
}

#rosette:before {
  content: "";
  background-image: url('https://www.pottertour.co.uk/imagesAwards/lux-life-award-transparent-min.svg');
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  /* visibility: hidden; */
  animation: rosette-before 5s;
  animation-fill-mode: forwards;
  display: inline-block;
  height: 100%;
  position: absolute;
  width: 100%;
  opacity: 0;
}

@keyframes rosette-anim {
  95% {
    position: absolute;
    background: rgb(51, 55, 56);
    height: 137px;
    width: 142px;
    border-radius: 70px;
    transform: rotateY(2turn);
    top: 4px;
    right: 20px;
  }
  to {
    position: absolute;
    height: 137px;
    width: 142px;
    border-radius: 70px;
    transform: rotateY(3turn);
    background-color: rgb(164, 132, 60);
    z-index: 1;
    top: 4px;
    right: 26px;
  }
}

@keyframes rosette-before {
  99% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
<div id="rosette"></div>

伪元素的动画和过渡是 not supported by IE11。您可以创建 <div> 并使用 ID 为其编写 CSS 并避免使用伪。示例代码如下:

#rosette {
  z-index: 99;
  position: absolute;
  background-color: crimson;
  height: 100vh;
  width: 100vw;
  animation: rosette-anim 5s;
  animation-fill-mode: forwards;
  content: "";
  transform-style: preserve-3d;
  background: rgb(51, 55, 56);
  top: 0px;
  right: 0px;
  transform: rotateY(0.5turn);
}

@keyframes rosette-anim {
  95% {
    position: absolute;
    background: rgb(51, 55, 56);
    height: 137px;
    width: 142px;
    border-radius: 70px;
    transform: rotateY(2turn);
    top: 4px;
    right: 20px;
  }
  100% {
    position: absolute;
    height: 137px;
    width: 142px;
    border-radius: 70px;
    transform: rotateY(3turn);
    background: rgb(164, 132, 60);
    background-size: 139px 100px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 1;
    top: 4px;
    right: 26px;
  }
}

#before {
  content: '';
  position: absolute;
  border-bottom: 90px solid rgb(164, 132, 60);
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  top: 95px;
  right: 80px;
  transform: translateZ(-1px) rotate(-140deg);
  opacity: 0;
  z-index: -1;
  animation: change 5s;
  animation-fill-mode: forwards;
}

#after {
  content: '';
  position: absolute;
  border-bottom: 90px solid rgb(164, 132, 60);
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  top: 95px;
  left: auto;
  right: 10px;
  transform: translateZ(-1px) rotate(140deg);
  opacity: 0;
  z-index: -1;
  animation: change 5s;
  animation-fill-mode: forwards;
}

@keyframes change {
  99% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
<div id="rosette"><img src="https://www.pottertour.co.uk/imagesAwards/lux-life-award-transparent-min.svg" id="award" alt="My private Harry Potter tours won Lux Life magazine&#39;s award for best pop culture tour Edinburgh, they anointed it &#39;Truly magical&#39;, bless them."
  /></div>
<div id="before"></div>
<div id="after"></div>

在 IE11 中的结果: