使用CSS创建此旋转动画

时间:2013-09-10 10:03:39

标签: css css3 css-animations

这是我想用CSS做的动画。 This spinner is what I'd like to create

这是一个动画PNG。 Firefox是我所知道的唯一可以显示动画的浏览器。请在FireFox中查看此内容,以便您可以看到动画。我想尝试在CSS中使用它,这样我就可以在更多的浏览器中使用它,并且仍然可以获得真正的透明度(GIF动画无法提供)

enter image description here< - 这是一个点,可用于制作动画而无需在css中创建点的阴影。

这个小提琴http://jsfiddle.net/jvrvK/显示了我到目前为止的所作所为。我看看球体的外观,但动画似乎不适用于Chrome,我不太了解CSS动画,足以在PNG中创建相同类型的旋转。

非常感谢您的帮助!

下面的小提琴代码:

<ul class="busy">
    <li class="busy-dot1"><b class="busy-dot-shine"></b></li>
    <li class="busy-dot2"><b class="busy-dot-shine"></b></li>
    <li class="busy-dot3"><b class="busy-dot-shine"></b></li>
    <li class="busy-dot4"><b class="busy-dot-shine"></b></li>
    <li class="busy-dot5"><b class="busy-dot-shine"></b></li>
</ul>
.busy {
    list-style: none;
    padding: 0;
    position: relative;
    transform-style: preserve-3d;
    animation: rot 4s linear infinite;
    width:100px;
}

.busy-dot1, .busy-dot2, .busy-dot3, .busy-dot4, .busy-dot5 {
    border-radius: 50%;
    display: inline-block;
    transform-style: preserve-3d;
    margin: 0 4px;
}

.busy-dot-shine {
    display: block;
    border-radius: 50%;
    background: radial-gradient(circle at 25% 25%, #FFF, rgba(255,255,255,0));
    background-color: #193987;
    animation: rotr 4s linear infinite;
    height: 20px;
    width: 20px;
}

4 个答案:

答案 0 :(得分:5)

Chrome可以对前缀进行挑剔,将PrefixFree库添加到您的代码中。你可以自己添加前缀,但我发现PreFix Free更容易。

//cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js

http://jsfiddle.net/adrianjmartin/jvrvK/2/

另一种方法是使用SVG: http://jsfiddle.net/adrianjmartin/AcvE5/3/

答案 1 :(得分:4)

这将是一个近似的解决方案

demo

HTML与您拥有的相同; CSS是

.busy {
    list-style: none;
    padding: 0;
    position: relative;
    width:100px;
}

.busy-dot1, .busy-dot2, .busy-dot3, .busy-dot4, .busy-dot5 {
    border-radius: 50%;
    display: inline-block;
    position: absolute;
    left: 150px;
    top: 50px;
    -webkit-animation: rot 4s linear infinite;
    animation: rot 4s linear infinite;
}

.busy-dot2 {
    -webkit-animation-delay: -3.5s;
    animation-delay: -3.5s;
}
.busy-dot3 {
    -webkit-animation-delay: -3s;
    animation-delay: -3s;
}
.busy-dot4 {
    -webkit-animation-delay: -2.7s;
    animation-delay: -2.7s;
}

.busy-dot-shine {
    display: block;
    border-radius: 50%;
    background: radial-gradient(circle at 25% 25%, #FFF, rgba(255,255,255,0));
    background-color: #193987;
    height: 20px;
    width: 20px;
}
.busy-dot2 .busy-dot-shine {
    height: 15px;
    width: 15px;
}
.busy-dot3 .busy-dot-shine {
    height: 10px;
    width: 10px;
}
.busy-dot4 .busy-dot-shine {
    height: 6px;
    width: 6px;
}

@-webkit-keyframes rot {
    0% {-webkit-transform: scaleX(2) rotate(0deg) translateX(50px) scale(1) rotate(0deg) scaleX(0.5);   
        opacity: 0.5;}
   25% {-webkit-transform: scaleX(2) rotate(90deg) translateX(50px) scale(1.5) rotate(-90deg) scaleX(0.5);
        opacity: 0.8;}
   50% {-webkit-transform: scaleX(2) rotate(180deg) translateX(50px) scale(1) rotate(-180deg) scaleX(0.5);
        opacity: 0.5;}
   75% {-webkit-transform: scaleX(2) rotate(270deg) translateX(50px) scale(0.8) rotate(-270deg) scaleX(0.5);
   opacity: 0.2;}
  100% {-webkit-transform: scaleX(2) rotate(360deg) translateX(50px) scale(1) rotate(-360deg) scaleX(0.5);
  opacity: 0.5;}
}

@keyframes rot {
    0% {transform: scaleX(2) rotate(0deg) translateX(50px) scale(1) rotate(0deg) scaleX(0.5);   
        opacity: 0.5;}
   25% {transform: scaleX(2) rotate(90deg) translateX(50px) scale(1.5) rotate(-90deg) scaleX(0.5);
        opacity: 0.8;}
   50% {transform: scaleX(2) rotate(180deg) translateX(50px) scale(1) rotate(-180deg) scaleX(0.5);
        opacity: 0.5;}
   75% {transform: scaleX(2) rotate(270deg) translateX(50px) scale(0.8) rotate(-270deg) scaleX(0.5);
        opacity: 0.2;}
  100% {transform: scaleX(2) rotate(360deg) translateX(50px) scale(1) rotate(-360deg) scaleX(0.5);
        opacity: 0.5;}
}

诀窍是设置一个在X中缩放2次的变换(在旋转时生成一个椭圆),然后旋转并平移以形成一个圆。

然后应用刻度使圆圈变大,最后反向旋转以使球体看起来正确

当然,所有值都是近似的,GIF太小,无法判断是否准确

答案 2 :(得分:2)

<强> HTML:

<div id="all">
  <div id="box">
    <div id="circle"></div>
  </div>
  <div id="box" class="box2">
    <div id="circle" class="circle2"></div>
  </div>
  <div id="box" class="box3">
    <div id="circle" class="circle3"></div>
  </div>
  <div id="box" class="box4">
    <div id="circle" class="circle4"></div>
  </div>
  <div id="box" class="box5">
    <div id="circle" class="circle5"></div>
  </div>
</div>

<强> CSS:

#box {
    position: absolute;
    width: 50px;
    height: 50px;
}
.box2 {
    -webkit-transform: rotate(35deg);
}
.box3 {
    -webkit-transform: rotate(70deg);
}
.box4 {
    -webkit-transform: rotate(105deg);
}
.box5 {
    -webkit-transform: rotate(140deg);
}
.circle2 {
    -webkit-transform: scale(.8);
}
.circle3 {
    -webkit-transform: scale(.6);
}
.circle4 {
    -webkit-transform: scale(.4);
}
.circle5 {
    -webkit-transform: scale(.2);
}
#circle {
    position: relative;
    top: 0px;
    left: 50px;
    border-radius: 50%;
    background: radial-gradient(circle at 25% 25%, #FFF, rgba(255, 255, 255, 0));
    background-color: #193987;
    animation: rotr 4s linear infinite;
    height: 20px;
    width: 20px;
}
#all {
    position: relative;
    top: 50px;
    left: 50px;
    width: 50px;
    height: 50px;

    animation: myfirst;
    animation-duration: 05s;
    animation-timing-function: linear;
    animation-iteration-count: infinite;

    -webkit-animation-name: myfirst;
    -webkit-animation-duration: 05s;
    -webkit-animation-timing-function: linear;
    -webkit-animation-iteration-count: infinite;
}
 @keyframes myfirst {
0% { transform: rotate(360deg);}
}
 @-webkit-keyframes myfirst {
0% { -webkit-transform: rotate(360deg);}
}

Live demo

答案 3 :(得分:1)

HTML:

<ul class="busy">
    <li class="busy-dot1"><b class="busy-dot-shine"></b></li>
</ul>

CSS:

.busy {
    list-style: none;
    padding: 0;
    position: relative;
    transform-style: preserve-3d;
    animation: rot 4s linear infinite;
    width:700px;
}

.busy-dot1, .busy-dot2, .busy-dot3, .busy-dot4, .busy-dot5 {
    border-radius: 50%;
    display: inline-block;
    transform-style: preserve-3d;
    margin: 0 4px;
}

.busy-dot-shine {
    display: block;
    border-radius: 50%;
    background: radial-gradient(circle at 25% 25%, #FFF, rgba(255,255,255,0));
    background-color: #193987;
    animation: rotr 4s linear infinite;
    height: 60px;
    width: 60px;
}
.busy li
{
transform:rotate(7deg);
-ms-transform:rotate(7deg); /* IE 9 */
-webkit-transform:rotate(7deg); /* Safari and Chrome */
animation:rotate 5s linear infinite;
-webkit-animation:rotate 5s linear infinite; /* Safari and Chrome */
}

@keyframes rotate
{
from {transform:rotate(0deg);
-ms-transform:rotate(0deg); /* IE 9 */
-webkit-transform:rotate(0deg); /* Safari and Chrome */}
to {transform:rotate(-180deg);
-ms-transform:rotate(-180deg); /* IE 9 */
-webkit-transform:rotate(-180deg); /* Safari and Chrome */}
}

@-webkit-keyframes rotate /* Safari and Chrome */
{
from {transform:rotate(0deg);
-ms-transform:rotate(0deg); /* IE 9 */
-webkit-transform:rotate(0deg); /* Safari and Chrome */}
to {transform:rotate(-360deg);
-ms-transform:rotate(-360deg); /* IE 9 */
-webkit-transform:rotate(-360deg); /* Safari and Chrome */}
}

请参阅操作:http://jsfiddle.net/Ld9pP/1/

你可能会选择另一个,但无论如何