用css实现一个类似于elementUI中Loading组件有缺口的加载圆环

直接上代码:

HTML部分

html 复制代码
<div id="app">
  <div class="loaderContainer">
    <div class="loaderContainer__icon"></div>
    <p class="loaderContainer__text">加载中...</p>
  </div>
</div>

CSS部分

css 复制代码
html,
body,
#app {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.loaderContainer {
  display: flex;
  flex-direction: column;
  align-items: center;

  .loaderContainer__icon {
    width: 42px;
    height: 42px;
    color: #0057ff;
    border-radius: 50%;
    border: 3px solid #0057ff;
    border-top-color: #ffffff;
    animation: spin 1s infinite linear;
    background-color: transparent;
  }

  .loaderContainer__text {
    margin-top: 10px;
    font-size: 14px;
    color: #0057ff;
  }
}

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

核心思想

1,使用一个div,设置宽高相等、再设置border-radius为50%,形成一个圆;

2,通过border给圆的边框设置宽度和颜色,并通过border-top-color设置和当前背景色一致,实现有缺口的视觉效果。

3,将圆的background-color设置为transparent透明,形成一个空心的圆环。

4,定义spin动画,使圆环旋转,实现加载的视觉效果

相关推荐
chilavert3181 天前
技术演进中的开发沉思-371:final 关键字(中)
java·前端·数据库
2301_816997881 天前
Vite构建工具
前端
yuki_uix1 天前
深入理解 reduce:从面试题到设计思维
前端
凌云拓界1 天前
TypeWell全攻略(二):热力图渲染引擎,让键盘发光
前端·后端·python·计算机外设·交互·pyqt·数据可视化
coding随想1 天前
TypeScript 高级类型全攻略:从“可表达性”到“类型体操”的实践之路
前端·javascript·typescript
大时光1 天前
gsap -滚动插件 ScrollTrigger 简单demo
前端
tangbin5830851 天前
iOS Swift:蓝牙 BLE 连接外设CoreBluetooth
前端
WWWWW先生1 天前
02 登录功能实现
前端·javascript