两种风格的纯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>

页面效果:

相关推荐
诸葛亮的芭蕉扇8 分钟前
tree组件点击节点间隙的异常问题分析
前端·javascript·vue.js
GinoWi31 分钟前
HTML基本格式 - 第一个HTML网页
前端
顶鲜花的牛粪35 分钟前
Astro 项目升级全栈:EdgeOne Pages 部署指南
前端
0***R5151 小时前
前端云原生
前端·云原生
月弦笙音1 小时前
【Promise.withResolvers】发现这个api还挺有用
前端·javascript·typescript
疯狂踩坑人1 小时前
MCP理论和实战,然后做个MCP脚手架吧
前端·node.js·mcp
中杯可乐多加冰1 小时前
基于 DeepSeek + MateChat 的证券智能投顾技术实践:打造金融领域的专属大Q模型助手
前端·人工智能
凡人程序员1 小时前
搭建简易版monorepo + turborepo
前端·javascript
丸子哥哥1 小时前
同一个域名,如何添加多个网站?
服务器·前端·nginx·微服务
不努力也不会混1 小时前
vite联邦实现微前端(vite-plugin-federation)
前端·vue.js