|
|
|
|
|
本文介紹3個(gè)漂亮的CSS動(dòng)畫進(jìn)度條,它們都是用純CSS來實(shí)現(xiàn)的,但進(jìn)度條樣式設(shè)計(jì)得很漂亮,值得推薦使用。
本實(shí)例的動(dòng)畫進(jìn)度條,均用純CSS來實(shí)現(xiàn)。
HTML代碼只有兩個(gè)DIV標(biāo)簽,使用三個(gè)CSS類。
<div class="container">
<div class="progress progress-striped">
<div class="progress-bar">
</div>
</div>
</div>
<div class="container">
<div class="progress2 progress-moved">
<div class="progress-bar2" >
</div>
</div>
</div>
<div class="container">
<div class="progress progress-infinite">
<div class="progress-bar3" >
</div>
</div>
</div>
每一個(gè)實(shí)例都使用三個(gè)CSS類,其中progress
和progress2
的作用是定義進(jìn)度條的背景樣式(邊距、背景顏色、邊角、陰影),代碼為
.progress {
padding: 6px;
background: rgba(0, 0, 0, 0.25);
border-radius: 6px;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
}
.progress2 {
padding: 6px;
border-radius: 30px;
background: rgba(0, 0, 0, 0.25);
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
}
此外,每個(gè)實(shí)例都還使用另外兩個(gè)不同的CSS類,實(shí)例1使用了progress-striped
和progress-bar
,實(shí)例2使用了progress-moved
和progress-bar2
,實(shí)例3使用了progress-infinite
和progress-bar3
,它們是進(jìn)度條的主要代碼,除了設(shè)置進(jìn)度條樣式,還設(shè)置動(dòng)畫。
body {
font-family: "Montserrat", sans-serif;
background: #2c303a;
}
.container {
margin: 100px auto;
width: 500px;
text-align: center;
}
.progress {
padding: 6px;
background: rgba(0, 0, 0, 0.25);
border-radius: 6px;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
}
.progress-bar {
height: 18px;
background-color: #ee303c;
border-radius: 4px;
transition: 0.4s linear;
transition-property: width, background-color;
}
.progress-striped .progress-bar {
background-color: #FCBC51;
width: 100%;
background-image: linear-gradient(45deg, #fca311 25%, transparent 25%, transparent 50%, #fca311 50%, #fca311 75%, transparent 75%, transparent);
animation: progressAnimationStrike 6s;
}
@keyframes progressAnimationStrike {
from {
width: 0;
}
to {
width: 100%;
}
}
.progress2 {
padding: 6px;
border-radius: 30px;
background: rgba(0, 0, 0, 0.25);
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
}
.progress-bar2 {
height: 18px;
border-radius: 30px;
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
transition: 0.4s linear;
transition-property: width, background-color;
}
.progress-moved .progress-bar2 {
width: 85%;
background-color: #EF476F;
animation: progressAnimation 6s;
}
@keyframes progressAnimation {
0% {
width: 5%;
background-color: #F9BCCA;
}
100% {
width: 85%;
background-color: #EF476F;
}
}
.progress-bar3 {
height: 18px;
border-radius: 4px;
background-image: linear-gradient(to right, #4cd964, #5ac8fa, #007aff, #7DC8E8, #5856d6, #ff2d55);
transition: 0.4s linear;
transition-property: width, background-color;
}
.progress-infinite .progress-bar3 {
width: 100%;
background-image: linear-gradient(to right, #4cd964, #5ac8fa, #007aff, #7DC8E8, #5856d6, #ff2d55);
animation: colorAnimation 1s infinite;
}
@keyframes colorAnimation {
0% {
background-image: linear-gradient(to right, #4cd964, #5ac8fa, #007aff, #7DC8E8, #5856d6, #ff2d55);
}
20% {
background-image: linear-gradient(to right, #5ac8fa, #007aff, #7DC8E8, #5856d6, #ff2d55, #4cd964);
}
40% {
background-image: linear-gradient(to right, #007aff, #7DC8E8, #5856d6, #ff2d55, #4cd964, #5ac8fa);
}
60% {
background-image: linear-gradient(to right, #7DC8E8, #5856d6, #ff2d55, #4cd964, #5ac8fa, #007aff);
}
100% {
background-image: linear-gradient(to right, #5856d6, #ff2d55, #4cd964, #5ac8fa, #007aff, #7DC8E8);
}
}
本文介紹了3個(gè)漂亮的動(dòng)畫進(jìn)度條,代碼簡(jiǎn)潔易理解,最主要的是它們都是純CSS實(shí)現(xiàn),這是大家喜歡的,也是值得推薦使用的主要原因。