今天要介紹,如何使用 CSS 漸變和動畫來製作加載進度條效果
<div class="progress-bar">
<div class="progress"></div>
</div>
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #f4f4f4;
font-family: Arial, sans-serif;
}
flex
使進度條在頁面中居中顯示.progress-bar {
width: 50%;
height: 30px;
background-color: #e0e0e0;
border-radius: 15px;
overflow: hidden;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}
.progress {
height: 100%;
background: linear-gradient(90deg, #99CCFF, #FFB2FF);
width: 0;
border-radius: 15px;
animation: load 5s ease-in-out infinite;
}
@keyframes load
動畫@keyframes load {
0% {
width: 0;
}
50% {
width: 100%;
}
100% {
width: 0;
}
}