在 CSS3 中,加载动画通常通过 @keyframes + animation 来实现,也可以结合 transform、opacity 等属性。下面按常见类型给你几种实用做法。
<div class="loader"></div>
.loader {
width: 40px;
height: 40px;
border: 4px solid #eee;
border-top-color: #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
✅ 原理:
border-top-color 做高亮部分rotate 持续旋转<div class="dots">
<span></span>
<span></span>
<span></span>
</div>
.dots {
display: flex;
gap: 6px;
}
.dots span {
width: 10px;
height: 10px;
background: #333;
border-radius: 50%;
animation: bounce 1.2s infinite ease-in-out;
}
.dots span:nth-child(2) {
animation-delay: 0.2s;
}
.dots span:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes bounce {
0%, 80%, 100% {
transform: scale(0);
}
40% {
transform: scale(1);
}
}
<div class="bar"></div>
.bar {
width: 100%;
height: 4px;
background: linear-gradient(90deg, #3498db, #2ecc71);
background-size: 200% 100%;
animation: loading 1.5s infinite;
}
@keyframes loading {
0% {
background-position: 200% 0;
}
100% {
background-position: -200% 0;
}
}
.pulse {
width: 40px;
height: 40px;
background: #3498db;
border-radius: 50%;
animation: pulse 1s infinite;
}
@keyframes pulse {
0% {
transform: scale(0.8);
opacity: 0.7;
}
100% {
transform: scale(1.2);
opacity: 0;
}
}
animation: name duration timing-function delay iteration-count direction;
示例:
animation: spin 1s linear infinite;
| 属性 | 说明 |
|---|---|
| duration | 动画时间 |
| timing-function | 缓动方式 |
| iteration-count | 次数(infinite 无限) |
| direction | 方向(alternate 来回) |
transform / opacity(性能更好)will-change: transformdisplay:none如果你想要 特定风格(如:微信风格、Material、骨架屏、纯 CSS 无 JS),可以告诉我,我可以直接给你完整示例。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。