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>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
  	<!-- 弹跳加载动画 -->
    <div class="bouncing-loader">
      <div class="bouncing-loader-item"></div>
      <div class="bouncing-loader-item"></div>
      <div class="bouncing-loader-item"></div>
    </div>

	<!-- 旋转加载动画 -->
    <div class="spin-loading">
      <div class="loading"></div>
    </div>

	<!-- 点点点加载动画 -->
    <span class="dot">正在加载中<span class="dotted"></span></span>
  </body>
</html>
css 复制代码
/* style.css */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  display: flex;
}
/* 弹跳加载效果 */
.bouncing-loader,
.spin-loading,
.dot {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 150px;
  border: 1px solid #efefef;
  margin: 3rem;
}
.bouncing-loader-item {
  width: 16px;
  height: 16px;
  margin: 3rem 0.2rem;
  background-color: #0b16f1;
  border-radius: 50%;
  animation: bouncingLoader 0.6s infinite alternate;
}
.bouncing-loader-item:nth-child(2) {
  animation-delay: 0.2s;
}
.bouncing-loader-item:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes bouncingLoader {
  to {
    opacity: 0.1;
    transform: translate3d(0, -10px, 0);
  }
}

/* 旋转动画效果 */
.spin-loading .loading {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 100%;
  /* 锥形渐变 */
  background-image: conic-gradient(#0b16f1, 30%, #fff);
  /* 使用蒙版将中间变为透明 */
  -webkit-mask-image: radial-gradient(closest-side, transparent 80%, black 80%);
  /* 开启动画 */
  animation: spin 1s linear infinite reverse;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
/* ...动画效果 */
.dotted {
  display: inline-block;
  width: 20px;
}
.dotted::after {
  content: '';
  animation: dotted 2s infinite;
}
@keyframes dotted {
  0% {
    content: '...';
  }
  25% {
    content: '';
  }
  50% {
    content: '.';
  }
  75% {
    content: '..';
  }
  100% {
    content: '...';
  }
}
相关推荐
爷傲奈我何!3 分钟前
小程序中实现音频播放(原生 + uniapp)
前端·vue.js
Json_7 分钟前
uni-app 框架 调用蓝牙,获取 iBeacon 定位信标的数据,实现室内定位场景
前端·uni-app·蓝牙
日升8 分钟前
手把手带你掌握Zustand:轻量级React状态管理利器
前端·react.js·状态机
Copy_Paste_Coder8 分钟前
35岁大龄码农,用cursor独立做副业经历分享
前端·程序员
jqq66610 分钟前
(二)「造轮子」我也写了个Vue3脚手架!(项目环境搭建)
前端·javascript·vue.js
Json_11 分钟前
vue2 + element-ui 开发网站拼图小游戏-前端项目
前端·vue.js·element
顾名思远义14 分钟前
VxeGRid树形表格编辑难点
前端·vue.js
逆袭的小黄鸭15 分钟前
单线程下的高效协作:JavaScript 事件循环机制详解
前端·javascript
0基础学习者17 分钟前
按键消抖(用状态机实现)
前端·笔记·fpga开发·verilog·fpga
zooKevin19 分钟前
前端实现docx格式word文件预览,可以兼容原生、vue2、以及uni-app 项目,详细步骤。
前端·uni-app·word·docx