html - CSS3 动画中元素的旋转不平滑和连续

标签 html css animation css-animations

我想使用CSS3制作一个ajax加载动画。我想做的就是以恒定的速度连续旋转这些圆圈。这是我到目前为止所做的,但问题是动画不流畅;动画开始缓慢,中间快速,结束缓慢。

我在某处读到制作 animation-timing-function:linear; 可以做到这一点;我做到了,但现在仍在工作。但它仍然是一种缓动动画。

谁能告诉我怎样才能做到这一点。

标记:

<div class="ajax">
    <div class="round outer"></div>
    <div class="round inner"></div>
</div>

CSS:

.ajax {position: relative; }
        .round {border: 5px solid #555; position: absolute; height: 40px; width: 40px; border-radius: 50%; }
        .round.inner {margin: 12px; }
        .round.outer {padding: 12px; }
        .round.outer:before {content: ''; position: absolute; height: 7px; width: 5px; background: #fff; top: -5px; left: 29px;}
        .round.inner:after {content: ''; position: absolute; border: 5px solid transparent; border-bottom: 7px solid #555; left: 15px; top: -15px; }
        .round.inner:before {content: ''; position: absolute; width: 5px; height: 7px; background: #fff; bottom: -7px; left: 18px;}

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

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

        @keyframes ajax-rotate-c
        {
            from {transform: rotate(0deg);}
            to {transform: rotate(-360deg);}
        }

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

    .ajax .round {
        -webkit-animation-timing-function:linear;
        animation-timing-function:linear; 
        }
    .ajax .round.inner{
        animation: ajax-rotate 2s infinite;
        -webkit-animation: ajax-rotate 2s infinite; 
    }

    .ajax .round.outer{
        animation: ajax-rotate-c 2s infinite;
        -webkit-animation: ajax-rotate-c 2s infinite; 
    }

最佳答案

您需要将缓动函数指定为线性

.ajax .round.inner{
    animation: ajax-rotate 2s infinite linear;
    -webkit-animation: ajax-rotate 2s infinite linear; 
}

.ajax .round.outer{
    animation: ajax-rotate-c 2s infinite linear;
    -webkit-animation: ajax-rotate-c 2s infinite linear; 
}

这是fiddle

关于html - CSS3 动画中元素的旋转不平滑和连续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21697892/

相关文章:

javascript - AngularJS根据页面innerWidth改变主体宽度

html - 我可以在 angular2 模板中使用 '==' 和管道 ( | ) 吗?

css - Wordpress 后循环的边框,使用 Bootstrap 的网格

java - 同一节点上两个同时的 RotationTransition

html - ionic 3 中的 touchstart 和 touchend 事件

c# - 根据移动或桌面 HTML 和 CSS 更改图像

html - 从屏幕底部全宽 Bootstrap 模式弹出窗口

android - 这个 Android 组件叫什么?

c# - Storyboard /动画的 "handful"影响性能?

html - Tizen 上的 Android 应用程序