当前位置:首页 > CSS

css如何制作加载

2026-02-13 07:54:25CSS

使用CSS制作加载动画

纯CSS旋转动画

通过@keyframestransform属性创建一个简单的旋转加载动画:

.loader {
  width: 50px;
  height: 50px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

点状加载动画

创建三个跳动的圆点作为加载指示器:

.dot-loader {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  background-color: #3498db;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(2) {
  animation-delay: 0.2s;
}

.dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

进度条加载动画

创建一个从左到右填充的进度条效果:

.progress-loader {
  width: 100%;
  height: 4px;
  background-color: #f3f3f3;
  position: relative;
  overflow: hidden;
}

.progress-loader::before {
  content: "";
  position: absolute;
  left: -50%;
  height: 100%;
  width: 50%;
  background-color: #3498db;
  animation: loading 2s linear infinite;
}

@keyframes loading {
  from { left: -50%; }
  to { left: 100%; }
}

骨架屏加载效果

为内容未加载时创建占位效果:

.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

波浪形加载动画

创建类似波浪起伏的效果:

css如何制作加载

.wave-loader {
  display: flex;
  justify-content: center;
  gap: 6px;
  height: 40px;
}

.wave {
  width: 6px;
  height: 100%;
  background: linear-gradient(to top, #3498db, #2980b9);
  animation: wave 1s ease-in-out infinite;
}

.wave:nth-child(2) {
  animation-delay: 0.1s;
}

.wave:nth-child(3) {
  animation-delay: 0.2s;
}

.wave:nth-child(4) {
  animation-delay: 0.3s;
}

@keyframes wave {
  0%, 100% { height: 40%; }
  50% { height: 100%; }
}

这些CSS加载动画可以根据实际需求调整颜色、尺寸和动画时长。通过组合不同的动画属性和关键帧,可以创建各种视觉效果来指示加载状态。

标签: 加载css
分享给朋友:

相关文章

css页脚制作

css页脚制作

CSS页脚制作方法 固定定位页脚 使用position: fixed将页脚固定在页面底部,适用于需要始终显示的页脚。 footer { position: fixed; bottom: 0;…

css 制作表格

css 制作表格

CSS 制作表格的方法 使用 CSS 制作表格可以通过多种方式实现,包括原生 HTML 表格样式、Flexbox 布局或 Grid 布局。以下是几种常见的方法: 原生 HTML 表格样式 HTML…

css制作时钟

css制作时钟

CSS 制作时钟的方法 使用纯CSS和少量JavaScript可以创建一个动态的时钟。以下是实现步骤: HTML结构 <div class="clock"> <div…

div css制作导航

div css制作导航

导航栏的基本结构 使用HTML的<nav>标签包裹导航链接,内部通常采用无序列表<ul>和列表项<li>结构。示例代码如下: <nav> <…

react如何加载网页

react如何加载网页

使用 React 加载网页的方法 通过 iframe 嵌入网页 在 React 组件中,可以通过 iframe 标签直接加载外部网页。这种方式简单直接,适合嵌入第三方页面或静态内容。 imp…

css页脚制作

css页脚制作

CSS页脚制作方法 基础页脚结构 在HTML中创建页脚的基本结构,使用<footer>标签包裹内容: <footer> <div class="footer-con…