CSS CSS3 旋转动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14859322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS3 Spin Animation
提问by iambriansreed
I have reviewed quite a few demos and have no idea why I can't get the CSS3 spin to function. I am using the latest stable release of Chrome.
我已经查看了很多演示,但不知道为什么我不能让 CSS3 旋转运行。我正在使用最新的稳定版 Chrome。
The fiddle: http://jsfiddle.net/9Ryvs/1/
小提琴: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>
回答by Gabriele Petrioli
To use CSS3 Animation you must also define the actual animation keyframes (which you named spin
)
要使用 CSS3 动画,您还必须定义实际的动画关键帧(您命名的spin
)
Read https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_animationsfor more info
阅读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.
配置动画的时间后,您需要定义动画的外观。这是通过使用
@keyframes
at 规则建立两个或更多关键帧来完成的。每个关键帧都描述了动画元素在动画序列期间的给定时间应如何呈现。
Demo at http://jsfiddle.net/gaby/9Ryvs/7/
演示在http://jsfiddle.net/gaby/9Ryvs/7/
@-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);}
}
回答by Jezen Thomas
You haven't specified any keyframes. I made it work here.
您尚未指定任何关键帧。我让它在这里工作。
div {
margin: 20px;
width: 100px;
height: 100px;
background: #f00;
-webkit-animation: spin 4s infinite linear;
}
@-webkit-keyframes spin {
0% {-webkit-transform: rotate(0deg);}
100% {-webkit-transform: rotate(360deg);}
}
You can actually do lots of really cool stuff with this. Here is one I made earlier.
你实际上可以用它做很多非常酷的事情。这是我之前做的。
:)
:)
N.B.You can skip having to write out all the prefixes if you use -prefix-free.
注意如果您使用-prefix-free ,您可以跳过必须写出所有前缀。
回答by oriadam
As of latest Chrome/FF and on IE11 there's no need for -ms/-moz/-webkit prefix. Here's a shorter code (based on previous answers):
从最新的 Chrome/FF 和 IE11 开始,不需要 -ms/-moz/-webkit 前缀。这是一个较短的代码(基于以前的答案):
div {
margin: 20px;
width: 100px;
height: 100px;
background: #f00;
/* The animation part: */
animation-name: spin;
animation-duration: 4000ms;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
Live Demo: http://jsfiddle.net/9Ryvs/3057/
回答by Pere Pages
HTML with font-awesome glyphicon.
HTML 字体很棒的字形。
<span class="fa fa-spinner spin"></span>
CSS
CSS
@-moz-keyframes spin {
to { -moz-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
to {transform:rotate(360deg);}
}
.spin {
animation: spin 1000ms linear infinite;
}
回答by danday74
The only answer which gives the correct 359deg:
给出正确 359deg 的唯一答案:
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(359deg); }
}
&.active {
animation: spin 1s linear infinite;
}
Here's a useful gradient so you can prove it is spinning (if its a circle):
这是一个有用的渐变,因此您可以证明它正在旋转(如果它是一个圆圈):
background: linear-gradient(to bottom, #000000 0%,#ffffff 100%);
回答by miphe
For the sake of completion, here's a Sass / Compass example which really shortens the code, the compiled CSS will include the necessary prefixes etc.
为了完成起见,这里有一个 Sass / Compass 示例,它确实缩短了代码,编译后的 CSS 将包含必要的前缀等。
div
margin: 20px
width: 100px
height: 100px
background: #f00
+animation(spin 40000ms infinite linear)
+keyframes(spin)
from
+transform(rotate(0deg))
to
+transform(rotate(360deg))
回答by miphe
To rotate, you can use key frames and a transform.
要旋转,您可以使用关键帧和变换。
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;
}
@-webkit-keyframes spin {
from {
-webkit-transform:rotate(0deg);
}
to {
-webkit-transform:rotate(360deg);
}
}
回答by sudarshan
@keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
this will make you to answer the question
这会让你回答这个问题