css3动画

复习下css3 的动画, 都快不会写了,那会儿挺喜欢flash的,可惜了时代在前进。写这里就当是文档看吧

浏览器支持

Internet Explorer 10、Firefox 以及 Opera 支持 animation 属性。

Safari 和 Chrome 支持替代的 -webkit-animation 属性。

注释:Internet Explorer 9 以及更早的版本不支持 animation 属性。

定义和用法

animation 属性是一个简写属性,用于设置六个动画属性:

animation-name

animation-duration

animation-timing-function

animation-delay

animation-iteration-count

animation-direction

语法

animation: name duration timing-function delay iteration-count direction;

描述 备注
animation-name 规定需要绑定到选择器的 keyframe 名称 @keyframe { from {opcity:0} to {opcity:1}}
animation-duration 规定完成动画所花费的时间,以秒或毫秒计 必须规定否则,不执行动画
animation-timing-function 规定动画的速度曲线 可取值为 linear ,ease(淡入淡出),ease-in,ease-out ,ease-in-out,cubic-bezier(n,n,n,n)
animation-delay 规定在动画开始之前的延迟 定义动画开始前等待的时间,以秒或毫秒计。默认值是 0。单位为s
animation-iteration-count 规定动画应该播放的次数 可选值为  infinite(无限次)n(比如5次)
animation-direction 规定是否应该轮流反向播放动画 默认值normal,alternate 为动画应该轮流反向播放。左右左
animation-play-state 规定动画是否正在运行或暂停。 paused表示暂停状态,running表示运行状态
animation-fill-mode 动画在播放之前或之后,其动画效果是否可见。 none(默认) / forwards(动画完成后) / backwards(在动画显示之前) / both(两者);
关于keyfr​ame 的定义

Firefox 支持替代的 @-moz-keyframes 规则。

Opera 支持替代的 @-o-keyframes 规则。

Safari 和 Chrome 支持替代的 @-webkit-keyframes 规则。

取值支持 0-100% 和 from,to

@keyframes move {
0%   {top:0px;left:0px;}
25%  {top:200px;left:200px;}
50%  {top:100px;left:100px;}
75%  {top:200px;left:200px;}
100% {top:0px;left:0px;}
}
@keyframes move {
from {top:0px;left:0px;}
to {top:0px;left:100px;}
}

demo

写了一个例子,地球绕太阳转

以下是代码

<!-- html 部分 -->
<div style="700px;">
        <div class="t">
            <div class="t1"></div>
        </div>
    </div>
<!-- css 部分 -->
<style lang="less">
@keyframes t {
  from { transform: rotate(0deg);  }
  to { transform: rotate(360deg);  }
}
@-webkit-keyframes t {
  from { transform: rotate(0deg);  }
  to { transform: rotate(360deg);  }
}
.t {
  height: 500px;
   500px;
  position: relative;
  border-radius: 50%;
  transform: scale(.8);
  border: 1px solid #dedede;
  &::before {
    content: "";
     50px;
    height: 50px;
    background: radial-gradient(72px, #f00, #ff0, #080);
    border-radius: 50%;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -25px;
    margin-left: -25px;
    box-shadow: 0 0 37px #fcff4a;
  }
  .t1 {
    height: 20px;
    border-radius: 50%;
     20px;
    margin-top: -10px;
    top: 50%;
    left: -10px;
    background: radial-gradient(26px, #0082ff, #184608, #003ade);
    position: absolute;
    animation: t 3s infinite linear;
    transform-origin: 260px center;
  }
}
</style>

还有一个demo ,在这里 https://k-ui.xyz ,要等一会儿才会展示。

下一篇文章,再回忆一下,css渐变

[完]

原文地址:https://www.cnblogs.com/chuchur/p/9399626.html