CSS
animation
动画
CSS
animation
动画
CSS
animation
动画
deg( degree ) / dɪˈɡriː / 度数,度
语法
1
| animation: name duration timing-function delay iteration-count direction;
|
animation 属性是一个简写属性,用于设置六个动画属性,
- animation-name
- animation-duration
- animation-timing-function
- animation-delay
- animation-iteration-count
- animation-direction
注释:请始终规定 animation-duration 属性,否则时长为 0,就不会播放动画了。
关键帧 keyframes
keyframes
规则: 0%(from)是开头动画,100%(to)是当动画完成。
合法值:
0-100%
from (和0%相同)
to (和100%相同)
@keyframes: 设置动画帧
-1) from to
– 使用于简单的动画,只有起始帧和结束帧
– 北京 - 上海 直达
-2) 百分比
– 多用于复杂的动画,动画不止两帧
– 北京 - 上海 —> 北京 – 天津 — 深圳 — 上海
– 0% - 100%, 可以任意拆分
1 2 3 4 5 6 7 8 9
| > @keyframes: 设置动画帧 > -1) from to > -- 使用于简单的动画,只有起始帧和结束帧 > -- 北京 - 上海 直达 > -2) 百分比 > -- 多用于复杂的动画,动画不止两帧 > -- 北京 - 上海 ---> 北京 -- 天津 --- 深圳 --- 上海 > -- 0% - 100%, 可以任意拆分 >
|
demo1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <div class="foo">我从上往下移动</div> <style> @keyframes fei { from {top:0;} to {top:200px;} }
@-webkit-keyframes fei /* Safari and Chrome */ { from {top:0;} to {top:200px;} }
.foo { width: 100px; height: 100px; background: #ff6b81; position: relative; animation: fei 5s infinite; -webkit-animation: fei 5s infinite; } </style>
|
demo2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <div> <div class="fei spinner-border"></div> </div>
<style> @keyframes spinner-border { to { transform: rotate(360deg) } } .fei{ display: inline-block; width: 2rem; height: 2rem; vertical-align: text-bottom; border: .25em solid currentColor; border-right-color: transparent; border-radius: 50%; -webkit-animation: spinner-border .75s linear infinite; animation: spinner-border .75s linear infinite; } </style>
|
demo3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
<div class="fei-2" style="width: 100px;height: 100px;background-color:#ff6b81;"> <svg class="circular" viewBox="25 25 50 50"> <circle class="path" cx="50" cy="50" r="20" fill="none"></circle> </svg> </div> <style> @keyframes loading-dash { 0% { stroke-dasharray: 1,200; stroke-dashoffset: 0; } 50% { stroke-dasharray: 90,150; stroke-dashoffset: -40px; } 100% { stroke-dasharray: 90,150; stroke-dashoffset: -120px; } } .fei-2 .path { animation: loading-dash 1.75s linear infinite; stroke-dasharray: 90,150; stroke-dashoffset: 0; stroke-width: 2; stroke: #409eff; stroke-linecap: round; }
@keyframes loading-rotate{ 100% { transform: rotate(360deg); } } .circular{ display: inline; height: 42px; width: 42px; animation: loading-rotate 2s linear infinite; } </style>
|
2个动画属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <style> div { width:100px; height:100px; background:#ff6b81; position:relative; animation: mymove 5s infinite,message-tip-rotating 5s infinite; }
@keyframes mymove { from {left:0px;} to {left:200px;} }
@keyframes message-tip-rotating { 0% { transform: rotate(0) } to { transform: rotate(360deg) } } </style> <p>定义2个动画属性</p> <div>动画_fei</div>
|
其他
animation 属性
关键帧 keyframes
01
关键帧 keyframes
02
动画CSS