# 一、animation 属性也是一个简写属性,用于设置六个动画属性。
用法:animation: name duration timing-function delay iteration-count direction;
这六个属性值分别为:
| animation-name | 规定需要绑定到选择器的 keyframe 名称 | 
|---|
| animation-duration | 规定完成动画所花费的时间,以秒或毫秒计。 | 
| animation-timing-function | 规定动画的速度曲线。 | 
| animation-delay | 规定在动画开始之前的延迟。 | 
| animation-iteration-count | 规定动画应该播放的次数。 | 
| animation-direction | 规定是否应该轮流反向播放动画。 | 
# 1.animation-name
指定要绑定到选择器的关键帧的名称。使用方法:changeTips 就是我自定义的名字。也就是 animation 里面的 name 的值。
|  | @keyframes changeTips { | 
|  |     0%{ | 
|  |         width: 38px; | 
|  |     } | 
|  |  | 
|  |     50%{ | 
|  |         width: 52px; | 
|  |     } | 
|  |  | 
|  |     100%{ | 
|  |         width: 66px; | 
|  |     } | 
|  | } | 
# 2.animation-duration
定义动画完成一个周期需要多少秒或毫秒。
# 3.animation-delay
属性定义动画什么时候开始。
- 单位可以是秒(s)或毫秒(ms)。
- 单位可以是负值,-2s 表示动画立马开始,但跳过 2 秒进入动画,即前 2 秒的动画不执行,直接跳过前 2 秒进入动画。
- 类似音波的加载效果 demo 地址:http://codepen.io/aSuncat/pen/ALLNpE
# 4. animation-timing-function
指定动画将如何完成一个周期。
| 值 | 说明 | 
|---|
| linear | 动画从头到尾的速度是相同的。 | 
| ease | 默认。动画以低速开始,然后加快,在结束前变慢。 | 
| ease-in | 动画以低速开始。 | 
| ease-out | 动画以低速结束。 | 
| ease-in-out | 动画以低速开始和结束。 | 
| cubic-bezier(n,n,n,n) | 在 cubic-bezier 函数中自己的值。可能的值是从 0 到 1 的数值。 | 
| step-start | 在变化过程中,都是以下一帧的显示效果来填充间隔动画 | 
| step-end | 在变化过程中,都是以上一帧的显示效果来填充间隔动画 | 
| steps() | 可以传入两个参数,第一个是一个大于 0 的整数,他是将间隔动画等分成指定数目的小间隔动画,然后根据第二个参数来决定显示效果。第二个参数设置后其实和 step-start,step-end 同义,在分成的小间隔动画中判断显示效果。 | 
# 5. animation-iteration-count
定义动画应该播放多少次。
| 值 | 说明 | 
|---|
| n | 一个数字,定义应该播放多少次动画 | 
| infinite | 指定动画应该播放无限次(永远) | 
# 6.animation-direction
定义是否循环交替反向播放动画。
| 值 | 说明 | 
|---|
| normal | 默认值。动画按正常播放。 | 
| reverse | 动画反向播放。 | 
| alternate | 动画在奇数次(1、3、5…)正向播放,在偶数次(2、4、6…)反向播放。 | 
| alternate-reverse | 动画在奇数次(1、3、5…)反向播放,在偶数次(2、4、6…)正向播放。 | 
| initial | 设置该属性为它的默认值。 | 
| inherit | 从父元素继承该属性。 | 
- 如果动画被设置为只播放一次,该属性将不起作用。
- 动画循环播放时,每次都是从结束状态跳回到起始状态,再开始播放。animation-direction 属性可以重写该行为。
# 7.animation-fill-mode
规定当动画不播放时(当动画完成时,或当动画有一个延迟未开始播放时),要应用到元素的样式。
| 值 | 说明 | 
|---|
| none | 默认值。动画在动画执行之前和之后不会应用任何样式到目标元素。 | 
| forwards | 在动画结束后(由 animation-iteration-count 决定),动画将应用该属性值。 | 
| backwards | 动画将应用在 animation-delay 定义期间启动动画的第一次迭代的关键帧中定义的属性值。这些都是 from 关键帧中的值(当 animation-direction 为 “normal” 或 “alternate” 时)或 to 关键帧中的值(当 animation-direction 为 “reverse” 或 “alternate-reverse” 时)。 | 
| both | 动画遵循 forwards 和 backwards 的规则。也就是说,动画会在两个方向上扩展动画属性。 | 
| initial | 设置该属性为它的默认值。 | 
| inherit | 从父元素继承该属性。 | 
# 8.animation-play-state:指定动画是否正在运行或已暂停。
| 值 | 说明 | 
|---|
| paused | 指定暂停动画。 | 
| running | 指定正在运行的动画。 | 
- 在 JavaScript 中使用此属性在一个周期中暂停动画。
- 线条鼠标悬停开始动画 demo 地址:http://codepen.io/aSuncat/pen/BLLbko
# 二、动画相关
# 1.animation 的简写(即上述属性的介绍顺序)
|  | animation: name duration timing-function delay iteration-count direction fill-mode play-state; | 
具体化可以记成一下形式:
|  | animation:myAnim 1s linear 1s infinite alternate both running; | 
# 2.keyframes:定义动画规则,关键帧。
| 值 | 说明 | 
|---|
| animationname | 必需的。定义 animation 的名称。 | 
| keyframes-selector | 必需的。动画持续时间的百分比。 | 
| css-styles | 必需的。一个或多个合法的 CSS 样式属性 | 
# 2.1 写法自由
# 2.1.1 指定的变化时发生时使用%,或关键字 "from" 和 "to",这是和 0%到 100%相同。以下两段代码效果相同。
|  | @keyframes myAnim{ | 
|  |   from { background: #f00; } | 
|  |   50% { background: #0f0; } | 
|  |   to { background: yellowgreen; } | 
|  | } | 
|  | 12345 | 
|  | @keyframes myAnim{ | 
|  |   0% { background: #f00; } | 
|  |   50% { background: #0f0; } | 
|  |   100% { background: yellowgreen; } | 
|  | } | 
# 2.1.2 如果省略某个状态,浏览器会自动推算中间状态。但是,为了获得最佳的浏览器支持,应该始终定义 0%和 100%的选择器。
|  | @keyframes rainbow { | 
|  |   50% { background: orange } | 
|  |   to { background: yellowgreen } | 
|  | } | 
|  |  | 
|  | @keyframes rainbow { | 
|  |   to { background: yellowgreen } | 
|  | } | 
# 2.1.3 可以将多个状态写在一行。
|  | @keyframes myAnim{ | 
|  |   0%,100% { background: #f00; } | 
|  |   50% { background: #0f0;  | 
|  | } | 
# 3. 浏览器前缀
IE 10 和 Firefox(>= 16)支持没有前缀的 animation,firefox(<16)使用 - moz - 前缀,因为现在 firefox 的版本也都不低,所以 firefox 都直接使用没有前缀的 animation。
而 chrome,safari,opera 不支持,所以必须使用 webkit 前缀。
使用示例如下:
|  | div{ | 
|  | 	animation:myAnim 1s; | 
|  | 	-webkit-animation:myAnim 1s; | 
|  | } | 
|  | @keyframes myAnim{ | 
|  |   0% { background: #f00; } | 
|  |   50% { background: #0f0; } | 
|  |   100% { background: yellowgreen; } | 
|  | } | 
|  | @-webkit-keyframes myAnim{ | 
|  |   0% { background: #f00; } | 
|  |   50% { background: #0f0; } | 
|  |   100% { background: yellowgreen; } | 
|  | } | 
# 4. 定义动画时,必须定义动画的名称和动画的持续时间。如果省略持续时间,动画将无法运行,因为默认值是 0。
# 三、animate.css 动画分类
官方在线体验地址:https://animate.style/
# 1.Fading Entrances - 淡入、淡出
| 值 | 说明 | 
|---|
| fadeIn | 淡入 | 
| fadeInDown | 向下淡入 | 
| fadeInDownBig | 向下快速淡入 | 
| fadeInLeft | 从左淡入 | 
| fadeInLeftBig | 从左快速淡入 | 
| fadeInRight | 从右淡入 | 
| fadeInRightBig | 从右快速淡入 | 
| fadeInUp | 向上淡入 | 
| fadeInUpBig | 向上快速淡入 | 
| fadeOut | 淡出 | 
| fadeOutDown | 向下淡出 | 
| fadeOutDownBig | 向下快速淡出 | 
| fadeOutLeft | 向左淡出 | 
| fadeOutLeftBig | 向左快速淡出 | 
| fadeOutRight | 向右淡出 | 
| fadeOutRightBig | 向右快速淡出 | 
| fadeOutUp | 向上淡出 | 
| fadeOutUpBig | 向上快速淡出 | 
# 2.Bouncing Entrances - 弹跳进出
| 值 | 说明 | 
|---|
| bounceIn | 弹跳进入 | 
| bounceInDown | 向下弹跳进入 | 
| bounceInLeft | 从左弹跳进入 | 
| bounceInRight | 从右弹跳进入 | 
| bounceInUp | 向上弹跳进入 | 
| bounceOut | 弹跳退出 | 
| bounceOutDown | 向下弹跳退出 | 
| bounceOutLeft | 向左弹跳退出 | 
| bounceOutRight | 向右弹跳退出 | 
| bounceOutUp | 向上弹跳退出 | 
# 3.Zoom Entrances - 缩放进出
| 值 | 说明 | 
|---|
| zoomIn | 放大进入 | 
| zoomInDown | 向下放大进入 | 
| zoomInLeft | 从左放大进入 | 
| zoomInRight | 从右放大进入 | 
| zoomInUp | 向上放大进入 | 
| zoomOut | 缩小退出 | 
| zoomOutDown | 向下缩小退出 | 
| zoomOutLeft | 向左缩小退出 | 
| zoomOutRight | 向右缩小退出 | 
| zoomOutUp | 向上缩小退出 | 
# 4.Rotating Entrances - 旋转进出
| 值 | 说明 | 
|---|
| rotateIn | 顺时针旋转进入 | 
| rotateInDownLeft | 从左往下旋入 | 
| rotateInDownRight | 从右往下旋入 | 
| rotateInUpLeft | 从左往上旋入 | 
| rotateInUpRight | 从右往上旋入 | 
| rotateOut | 顺时针旋转退出 | 
| rotateOutDownLeft | 向左下旋出 | 
| rotateOutDownRight | 向右下旋出 | 
| rotateOutUpLeft | 向左上旋出 | 
| rotateOutUpRight | 向右上旋出 | 
# 5.flip - 翻转水平、垂直
| 值 | 说明 | 
|---|
| flip | 放大翻转缩小 | 
| flipInX | 水平翻转进入 | 
| flipInY | 垂直翻转进入 | 
| flipOutX | 水平翻转退出 | 
| flipOutY | 垂直翻转退出 | 
# 6.Sliding Entrances - 滑动进出
| 值 | 说明 | 
|---|
| slideInUp | 向上滑动进入 | 
| slideInDown | 向下滑动进入 | 
| slideInLeft | 从左滑动进入 | 
| slideInRight | 从右滑动进入 | 
| slideOutUp | 向上滑动退出 | 
| slideOutDown | 向下滑动退出 | 
| slideOutLeft | 向左滑动退出 | 
| slideOutRight | 向右滑动退出 | 
# 7.Attention seekers - 引人注目的
| 值 | 说明 | 
|---|
| bounce | 弹跳 | 
| flash | 闪烁 | 
| pulse | 脉冲 | 
| rubberBand | 橡皮筋 | 
| shake | 左右弱晃动 | 
| swing | 上下摆动 | 
| tada | 缩放摆动 | 
| wobble | 左右强晃动 | 
| jello | 拉伸抖动 | 
# 8.Lightspeed - 光速
| 值 | 说明 | 
|---|
| lightSpeedIn | 光速出现 | 
| lightSpeedOut | 光速消失 | 
# 9.Specials - 特殊的
| 值 | 说明 | 
|---|
| hinge | 悬挂,颤抖,掉下去 | 
| rollIn | 从左侧旋转进入 | 
| rollOut | 向右侧旋转消失 |