关键帧在IE11中无法正常工作

时间:2017-03-23 09:41:32

标签: html css css3 css-animations internet-explorer-11

我有一个选择框动画,其中选择框突出显示。显然,关键帧动画在Chrome中正常运行,但在IE11中无法正常运行。 我想知道我应该在代码中更改什么,以便它也可以在IE11中使用。

.animate-box{
    height: 100%;
    -moz-animation-duration: 0.5s;
      -webkit-animation-duration: 0.5s;
      -moz-animation-name: changeShadow;
      -webkit-animation-name: changeShadow;
      -moz-animation-iteration-count: infinite;
      -webkit-animation-iteration-count: infinite;
      -moz-animation-direction: alternate;
      -webkit-animation-direction: alternate;
    border: 1px solid black;
}
@-webkit-keyframes changeShadow{
  from {
    box-shadow: 0px 0px 10px #90a4b2;
  }

  to {
    box-shadow: 0px 0px 20px #337ab7;
  }
}

@-moz-keyframes changeShadow{
  from {
    box-shadow: 0px 0px 10px #90a4b2;
  }

  to {
    box-shadow: 0px 0px 20px #337ab7;
  }
}
<select class="animate-box">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

2 个答案:

答案 0 :(得分:3)

您必须为IE10 +添加CSS动画的无前缀属性,请在CanIUse?上查看。此外,您可以使用简写animation属性:

&#13;
&#13;
.animate-box {
    height: 100%;
    -webkit-animation: changeShadow 0.5s infinite alternate;
    -moz-animation: changeShadow 0.5s infinite alternate;
    animation: changeShadow 0.5s infinite alternate;
    border: 1px solid black;
}
@-webkit-keyframes changeShadow {
  from { box-shadow: 0 0 10px #90a4b2; }
  to { box-shadow: 0 0 20px #337ab7; }
}

@-moz-keyframes changeShadow {
  from { box-shadow: 0 0 10px #90a4b2; }
  to { box-shadow: 0 0 20px #337ab7; }
}

@keyframes changeShadow {
  from { box-shadow: 0 0 10px #90a4b2; }
  to { box-shadow: 0 0 20px #337ab7; }
}
&#13;
<select class="animate-box">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我发现我忘了向css添加动画属性并包含无前缀关键帧:

.animate-box{
    height: 100%;
    -moz-animation-duration: 0.5s;
    -webkit-animation-duration: 0.5s;
    animation-duration: 0.5s;
    -moz-animation-name: changeShadow;
    -webkit-animation-name: changeShadow;
    animation-name: changeShadow;
    -moz-animation-iteration-count: infinite;
    -webkit-animation-iteration-count: infinite;
    animation-iteration-count: infinite;
    -moz-animation-direction: alternate;
    -webkit-animation-direction: alternate;
    animation-direction: alternate;
    border: 1px solid black;
}

@keyframes changeShadow{
  from {
    box-shadow: 0px 0px 10px #90a4b2;
  }

  to {
    box-shadow: 0px 0px 20px #337ab7;
  }
}