【问题标题】:Why do CSS3 animations behave strangely when used in conjunction with CSS3 transitions?为什么 CSS3 动画在与 CSS3 过渡结合使用时表现异常?
【发布时间】:2012-02-14 07:54:38
【问题描述】:

请参阅this fiddle 了解我的意思的示例或查看此代码。

<a href="/">test</a>

a{
    background-color:#ccc;
    transition: all 1s ease;
    -moz-transition: all 1s ease;
    -o-transition: all 1s ease;
    -webkit-transition: all 1s ease;
}
a:hover{
    background-color:#888;
}

a{
    -moz-animation-duration: 3s;  
    -moz-animation-name: move;  
    -moz-animation-iteration-count: infinite;  
    -moz-animation-direction: alternate;  
}

@-moz-keyframes move {  
    from {  
      margin-left: 0px;
    }  

    to {  
      margin-left: 50px;
    }  
  }

动画偶尔会跳动或改变速度,尤其是当您将鼠标悬停在它上面时...我尝试过自己运行动画(没有定义过渡),它运行流畅且符合预期。我自己运行了过渡,它按预期工作。这种组合似乎会导致问题。

可能是 Firefox 实现错误?我正在运行 Firefox 6.0.1、Ubuntu 11.04。

【问题讨论】:

  • 在我的浏览器中工作正常吗?火狐 6.0.1 Win 7 专业版。
  • 那可能是 Linux 版 Firefox 特有的 bug?

标签: animation css


【解决方案1】:

您需要将“全部”替换为“背景”。然后它工作正常。我认为当您将鼠标悬停时,它将转换所有样式,因此 current-margin-left 到新的 margin-left 也是如此,这是相同的,因此在转换期间边距不会改变。之后动画再次优先,你会看到跳转。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 2012-06-14
    • 2011-10-11
    • 1970-01-01
    相关资源
    最近更新 更多