两种风格的纯CSS3加载动画

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>加载动画</title>
    <style>
      .loader {
        width: 30px;
        height: 30px;
        border-radius: 50%;
        border: 4px solid #f3f3f3;
        border-top: 4px solid #3498db;
        animation: spin 1s linear infinite;
        margin: 0 auto;
      }

      @keyframes spin {
        0% {
          transform: rotate(0deg);
        }
        100% {
          transform: rotate(360deg);
        }
      }
      .spin {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin: 50px;
        width: 200px;
        height: 200px;
        border: 1px solid #999;
      }
      .spin span {
        margin-top: 5px;
      }
      .container {
        display: flex;
      }

      .dots {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 200px;
        height: 200px;
        margin: 50px;
        border: 1px solid #999;
      }
      
     
      .dot {
        width: 10px;
        height: 10px;
        background-color: #ccc;
        border-radius: 50%;
        margin: 0 3px;
        opacity: 0.4;
        animation: loading 1.2s infinite;
      }

      .dot:nth-child(1) {
        animation-delay: 0.1s;
      }

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

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

      @keyframes loading {
        0% {
          transform: scale(1);
          opacity: 0.4;
        }
        50% {
          opacity: 1;
          transform: scale(1.2);
        }
        100% {
          opacity: 0.4;
          transform: scale(1);
        }
      }
    </style>
  </head>
  <body>
    <div class="container">
      <!-- 第一种动画 -->
      <div class="spin">
        <div class="loader"></div>
        <span>加载中...</span>
      </div>

      <!-- 第二种动画 -->
      <div class="dots">
        <span class="dot"></span>
        <span class="dot"></span>
        <span class="dot"></span>
      </div>
    </div>
  </body>
</html>

页面效果:

相关推荐
@PHARAOH1 小时前
WHAT - GitLens vs Fork
前端
yqcoder2 小时前
前端性能优化:如何减少重绘与重排?
前端·性能优化
洋子2 小时前
Yank Note 系列 13 - 让 AI Agent 进入笔记工作流
前端·人工智能
wenzhangli75 小时前
Ooder A2UI 核心架构深度解析:WEB 拦截层的设计与实现
前端·架构
前端百草阁5 小时前
【前端性能优化全链路指南】从开发编写到构建运行的多维度实践
前端·性能优化
女生也可以敲代码5 小时前
AI时代下的50道前端开发面试题:从基础到大模型应用
前端·面试
ZhengEnCi5 小时前
M5-markconv自定义CSS样式指南 📝
前端·css·python
IT_陈寒6 小时前
SpringBoot自动配置的坑差点让我加班到天亮
前端·人工智能·后端
xingpanvip6 小时前
星盘接口开发文档:星相日历接口指南
android·开发语言·前端·css·php·lua
@PHARAOH6 小时前
WHAT - GitLens supercharged 插件
前端