CSS动画在IE和Edge中不起作用

时间:2016-06-26 06:25:52

标签: css css3 internet-explorer css-animations microsoft-edge

我有以下CSS代码,它是一个很好的声纳效果应用于悬停元素。它在Firefox,Opera和Chrome中运行良好 但我也无法在IE(10+)和Edge中使用它。



body {
  background-color: #cccccc;
}
.text {
  position: realtive;
  display: block;
  width: 85px;
  margin: 150px auto 0px;
  background-color: #;
}
.content {
  display: block;
  position: relative;
  height: 100px;
  width: 100px;
  border: 2px solid white;
  border-radius: 100%;
  margin: 20px auto;  
}
.icon {
  display: block;
  height: 100px;
  width: 100px;
  background-color: red;
}
.whiteSonarEffect .icon {
   border-radius: 100%;
   position: relative;
}
.whiteSonarEffect .icon:after {
   position: absolute;
   width: 100%;
   height: 100%;
   border-radius: 100%;
   content:'';
   -webkit-box-sizing: content-box;
   -moz-box-sizing: content-box;
   box-sizing: content-box;
   top: 0;
   left: 0;
}
.whiteSonarEffect .icon:hover {
   color: #fff;
}
.whiteSonarEffect .content:hover .icon:after {
   -webkit-animation: whiteSonarEffect 1.3s ease-out 75ms;
   -moz-animation: whiteSonarEffect 1.3s ease-out 75ms;
   -o-animation: whiteSonarEffect 1.3s ease-out 75ms;
   animation: whiteSonarEffect 1.3s ease-out 75ms;
}
@-webkit-keyframes whiteSonarEffect {
   0% {
       opacity: 0.3;
   }
   40% {
       opacity: 0.5;
       box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
   }
   100% {
       box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
       -webkit-transform: scale(1.5);
       opacity: 0;
   }
}
@-moz-keyframes whiteSonarEffect {
   0% {
       opacity: 0.3;
   }
   40% {
       opacity: 0.5;
       box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
   }
   100% {
       box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
       -moz-transform: scale(1.5);
       opacity: 0;
   }
}
@-o-keyframes whiteSonarEffect {
   0% {
       opacity: 0.3;
   }
   40% {
       opacity: 0.5;
       box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
   }
   100% {
       box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
       -o-transform: scale(1.5);
       opacity: 0;
   }
}
@keyframes whiteSonarEffect {
   0% {
       opacity: 0.3;
   }
   40% {
       opacity: 0.5;
       box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
   }
   100% {
       box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
       transform: scale(1.5);
       opacity: 0;
   }
}

<div class="whiteSonarEffect">
  <div class="text"><h3>Hover Me</h3></div>
 <div class="content">
    <div class="icon"></div>
 </div>
</div>
&#13;
&#13;
&#13;

您可以在CodePen上查看它:http://codepen.io/ivanchi/pen/YWNjVN 将不胜感激任何建议。

1 个答案:

答案 0 :(得分:3)

我过去遇到过类似的问题(不记得何时何地),但IE也需要在box-shadow关键帧中设置0%。在下面的代码段中,我添加了与box-shadow关键帧中相同的40%,但为所有阴影提供了alpha = 0的颜色,以确保它不可见。

适用于IE11,Edge,Chrome,Opera和Firefox。

body {
  background-color: #cccccc;
}
.text {
  position: realtive;
  display: block;
  width: 85px;
  margin: 150px auto 0px;
  background-color: #;
}
.content {
  display: block;
  position: relative;
  height: 100px;
  width: 100px;
  border: 2px solid white;
  border-radius: 100%;
  margin: 20px auto;
}
.icon {
  display: block;
  height: 100px;
  width: 100px;
  background-color: red;
}
.whiteSonarEffect .icon {
  border-radius: 100%;
  position: relative;
}
.whiteSonarEffect .icon:after {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 100%;
  content: '';
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
  top: 0;
  left: 0;
}
.whiteSonarEffect .icon:hover {
  color: #fff;
}
.whiteSonarEffect .content:hover .icon:after {
  -webkit-animation: whiteSonarEffect 1.3s ease-out 75ms;
  -moz-animation: whiteSonarEffect 1.3s ease-out 75ms;
  -o-animation: whiteSonarEffect 1.3s ease-out 75ms;
  animation: whiteSonarEffect 1.3s ease-out 75ms;
}
@-webkit-keyframes whiteSonarEffect {
  0% {
    opacity: 0.3;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0), 0 0 10px 10px rgba(255, 255, 255, 0), 0 0 0 10px rgba(255, 255, 255, 0);
  }
  40% {
    opacity: 0.5;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
  }
  100% {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
    -webkit-transform: scale(1.5);
    opacity: 0;
  }
}
@-moz-keyframes whiteSonarEffect {
  0% {
    opacity: 0.3;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0), 0 0 10px 10px rgba(255, 255, 255, 0), 0 0 0 10px rgba(255, 255, 255, 0);
  }
  40% {
    opacity: 0.5;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
  }
  100% {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
    -moz-transform: scale(1.5);
    opacity: 0;
  }
}
@-o-keyframes whiteSonarEffect {
  0% {
    opacity: 0.3;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0), 0 0 10px 10px rgba(255, 255, 255, 0), 0 0 0 10px rgba(255, 255, 255, 0);
  }
  40% {
    opacity: 0.5;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
  }
  100% {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
    -o-transform: scale(1.5);
    opacity: 0;
  }
}
@keyframes whiteSonarEffect {
  0% {
    opacity: 0.3;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0), 0 0 10px 10px rgba(255, 255, 255, 0), 0 0 0 10px rgba(255, 255, 255, 0);
  }
  40% {
    opacity: 0.5;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
  }
  100% {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 10px 10px #fff, 0 0 0 10px rgba(255, 255, 255, 0.5);
    transform: scale(1.5);
    opacity: 0;
  }
}
<div class="whiteSonarEffect">
  <div class="text">
    <h3>Hover Me</h3>
  </div>
  <div class="content">
    <div class="icon"></div>
  </div>
</div>