標籤:running 動畫 add gradient 運行 實現 eps float inf
一。css3中animation動畫各種屬性詳解:
animation
Value: [<animation-name> || <animation-duration> || <animation-timing-function> || <animation-delay> || <animation-iteration-count> || <animation-direction> || <animation-fill-mode>] [, [<animation-name> || <animation-duration> || <animation-timing-function> || <animation-delay> || <animation-iteration-count> || <animation-direction> || <animation-fill-mode>] ]*
animation-timing-function:
定義動畫的速度曲線
ease:動畫以低速開始,然後加快,在結束前變慢。
linear:勻速
ease-in:動畫以低速開始
ease-out:動畫以低速結束
ease-in-out:動畫以低速開始和結束,相對於ease緩慢,速度更均勻
step-start:按keyframes設定逐幀顯示,第一幀為keyframes設定的第一幀。
step-end:按keyframes設定逐幀顯示,第一幀為樣式的初始值。
steps(<number>[, [ start | end ] ]?):把keyframes裡設定的一幀等分為幾幀,start為第一次顯示第一幀,end第一次顯示樣式的初始值,例如:steps(4,start)
cubic-bezier(<number>, <number>, <number>, <number>):在 cubic-bezier 函數中自己的值。可能的值是從 0 到 1 的數值。貝茲曲線限制了首尾兩控制點的位置,通過調整中間兩控制點的位置可以靈活得到常用的動畫效果
animation-iteration-count
動畫迭代次數,預設就1次,可以設定2次,3次,4次,…infinite表示無限
animation-duration
指一個動畫周期期間。單位秒s或毫秒ms.
animation-delay
指動畫延時執行時間。單位秒s或毫秒ms.
animation-direction
指動畫時間軸上幀前進的方向。
normal:預設值,表示一直向前,最後一幀結束後回到第一幀
reverse:與normal的運行方向相反
alternate:往前播放完了之後,然後再倒帶,倒帶到頭了再往後播放
alternate-reverse:與alternate的運行方向相反
animation-fill-mode
設定動畫結束後的狀態
none:預設值。不設定對象動畫之外的狀態,DOM未進行動畫前狀態
forwards:設定對象狀態為動畫結束時的狀態,100%或to時,當設定animation-direcdtion為reverse時動畫結束後顯示為keyframes第一幀
backwards:設定對象狀態為動畫開始時的狀態,(測試顯示DOM未進行動畫前狀態)
both:設定對象狀態為動畫結束或開始的狀態,結束時狀態優先
animation-play-state
paused:設定該屬性使動畫暫停
running:設定該屬性使動畫繼續播放
動畫運行狀態,暫停或繼續播放,屬性為:running(預設)以及paused. 這個什麼時候有用的,使用animation實現視頻播放效果的時候
二。demo
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
.box{
width: 100%;
padding: 3%;
box-sizing: border-box;
overflow: hidden;
}
.box .loader{
width: 30%;
float: left;
height: 200px;
margin-right: 3%;
border:1px solid #ccc;
display: flex;
align-items: center;
justify-content: center;
}
@-webkit-keyframes loading-1{
0%{
transform: rotate(0deg);
}
50%{
transform: rotate(180deg);
}
100%{
transform: rotate(360deg);
}
}
.loading-1{
width: 35px;
height: 35px;
position: relative;
}
.loading-1 i{
width: 100%;
height: 100%;
display: block;
border-radius: 50%;
background: linear-gradient(transparent 0%,transparent 70%, #333 30%,#333 100%);
-webkit-animation: loading-1 0.6s linear 0s infinite;
}
@-webkit-keyframes loading-2{
0%{
transform: scaleY(1);
}
50%{
transform: scaleY(0.5);
}
100%{
transform: scaleY(1);
}
}
.loading-2 i{
display: inline-block;
width: 4px;
height: 35px;
border-radius: 2px;
margin: 0 2px;
background-color: #ccc;
}
.loading-2 i:nth-child(1){
-webkit-animation:loading-2 1s ease-in 0.1s infinite;
}
.loading-2 i:nth-child(2){
-webkit-animation:loading-2 1s ease-in 0.2s infinite;
}
.loading-2 i:nth-child(3){
-webkit-animation:loading-2 1s ease-in 0.3s infinite;
}
.loading-2 i:nth-child(4){
-webkit-animation:loading-2 1s ease-in 0.4s infinite;
}
.loading-2 i:nth-child(5){
-webkit-animation:loading-2 1s ease-in 0.5s infinite;
}
@-webkit-keyframes loading-3{
50%{
transform: scale(0.4);
opacity: 0.3;
}
100%{
transform: scale(1);
opacity:1;
}
}
.loading-3{
position: relative;
}
.loading-3 i{
display: block;
width: 15px;
height: 15px;
border-radius: 50%;
position: absolute;
background-color: #CCCCCC;
}
.loading-3 i:nth-child(1){
top:25px;
left: 0px;
-webkit-animation: loading-3 1s ease 0s infinite;
}
.loading-3 i:nth-child(2){
top:17px;
left: 17px;
-webkit-animation: loading-3 1s ease -0.12s infinite;
}
.loading-3 i:nth-child(3){
top:0px;
left:25px;
-webkit-animation: loading-3 1s ease -0.24s infinite;
}
.loading-3 i:nth-child(4){
top:-17px;
left:17px;
-webkit-animation: loading-3 1s ease -0.36s infinite;
}
.loading-3 i:nth-child(5){
top:-25px;
left: 0px;
-webkit-animation: loading-3 1s ease -0.48s infinite;
}
.loading-3 i:nth-child(6){
top:-17px;
left: -17px;
-webkit-animation: loading-3 1s ease -0.6s infinite;
}
.loading-3 i:nth-child(7){
top:0px;
left:-25px;
-webkit-animation: loading-3 1s ease -0.72s infinite;
}
.loading-3 i:nth-child(8){
top:17px;
left:-17px;
-webkit-animation: loading-3 1s ease -0.84s infinite;
}
</style>
<body>
<div class="box">
<div class="loader">
<div class="loading-1">
<i></i>
</div>
</div>
<div class="loader">
<div class="loading-2">
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
</div>
</div>
<div class="loader">
<div class="loading-3">
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
</div>
</div>
</div>
</body>
</html>
css3實現的3中loading動畫效果