CSS3 旋转动画

标签 css css-animations

我已经查看了很多演示,但不知道为什么我无法让 CSS3 旋转功能发挥作用。我使用的是最新稳定版本的 Chrome。

fiddle : http://jsfiddle.net/9Ryvs/1/

div {
  margin: 20px;
  width: 100px;
  height: 100px;
  background: #f00;
  -webkit-animation-name: spin;
  -webkit-animation-duration: 40000ms;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-timing-function: linear;
  -moz-animation-name: spin;
  -moz-animation-duration: 40000ms;
  -moz-animation-iteration-count: infinite;
  -moz-animation-timing-function: linear;
  -ms-animation-name: spin;
  -ms-animation-duration: 40000ms;
  -ms-animation-iteration-count: infinite;
  -ms-animation-timing-function: linear;
  -o-transition: rotate(3600deg);
}
<div></div>

最佳答案

要使用 CSS3 动画,您还必须定义实际的动画关键帧(您将其命名为 spin)

阅读https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_animations了解更多信息

Once you've configured the animation's timing, you need to define the appearance of the animation. This is done by establishing two or more keyframes using the @keyframes at-rule. Each keyframe describes how the animated element should render at a given time during the animation sequence.


演示:

div {
    margin: 20px;
    width: 100px;
    height: 100px;
    background: #f00;
    -webkit-animation-name: spin;
    -webkit-animation-duration: 4000ms;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;
    -moz-animation-name: spin;
    -moz-animation-duration: 4000ms;
    -moz-animation-iteration-count: infinite;
    -moz-animation-timing-function: linear;
    -ms-animation-name: spin;
    -ms-animation-duration: 4000ms;
    -ms-animation-iteration-count: infinite;
    -ms-animation-timing-function: linear;
    
    animation-name: spin;
    animation-duration: 4000ms;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}
@-ms-keyframes spin {
    from { -ms-transform: rotate(0deg); }
    to { -ms-transform: rotate(360deg); }
}
@-moz-keyframes spin {
    from { -moz-transform: rotate(0deg); }
    to { -moz-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
    from { -webkit-transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
    from {
        transform:rotate(0deg);
    }
    to {
        transform:rotate(360deg);
    }
}
<div></div>

@-moz-keyframes spin {
    from { -moz-transform: rotate(0deg); }
    to { -moz-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
    from { -webkit-transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
    from {transform:rotate(0deg);}
    to {transform:rotate(360deg);}
}

关于CSS3 旋转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14859322/

相关文章:

css - 背景图片在手机上看起来很模糊

jquery - 我如何使用不同的颜色?

css - twitter bootstrap 3 选项卡 View 淡入淡出无法正常工作

html - 显示所有子级列表与 css 内联

css - 使用 transition-duration 使动画淡出

css - 带有 CSS 转换的 Web 应用程序上闪烁的黑色方 block

css - 是否可以使用浏览器检查器检查 CSS3 动画关键帧?

javascript - 用新类替换类

css - Firefox svg 动画在特定 PC 上卡住

html - 如何使这个 css 动画响应?