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

直接上代码:

HTML部分

<div id="app">
  <div class="loaderContainer">
    <div class="loaderContainer__icon"></div>
    <p class="loaderContainer__text">加载中...</p>
  </div>
</div>

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动画,使圆环旋转,实现加载的视觉效果

好的,我可以给你提供一个简单的示例,帮助你实现一个类似ElementUI加载组件的自定义组件。 首先,你需要新建一个Vue组件。你可以在组件中添加一个包含加载动画的HTML元素。例如: ```html <template> <div class="loading-wrapper"> <div class="loader"></div> </div> </template> ``` 然后,你需要在组件中添加一些CSS样式,来制作加载动画。例如: ```css .loading-wrapper { display: flex; align-items: center; justify-content: center; height: 100%; } .loader { border: 16px solid #f3f3f3; border-top: 16px solid #3498db; border-radius: 50%; width: 120px; height: 120px; animation: spin 2s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } ``` 最后,你需要在Vue组件中添加一些逻辑代码,来控制加载组件的显示和隐藏。例如: ```html <template> <div v-show="loading" class="loading-wrapper"> <div class="loader"></div> </div> </template> <script> export default { data() { return { loading: false } }, methods: { showLoading() { this.loading = true }, hideLoading() { this.loading = false } } } </script> ``` 现在,你就可以在其他Vue组件中使用这个自定义组件了。例如: ```html <template> <div> <my-loading v-show="isLoading"></my-loading> <button @click="fetchData">点击加载数据</button> </div> </template> <script> import MyLoading from './MyLoading.vue' export default { components: { MyLoading }, data() { return { isLoading: false } }, methods: { fetchData() { this.isLoading = true // 发送请求获取数据 // 请求完成后隐藏加载组件 this.isLoading = false } } } </script> ``` 以上就是一个简单的自定义加载组件实现示例。你可以根据自己的需求,对这个示例进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

妍思码匠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值