使用vue3封装一个loading加载动画效果

<template>
  <div class="Loading">
    <div className="roots">
      <section>
        <div class="box"></div>
        <div class="box-circle"></div>
        <div class="box-circle1"></div>
        <div class="box-circle2"></div>
      </section>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
onMounted(() => { });
</script>

<style lang="less" scoped>
.Loading {
  .roots {
    --color: orange;
    --lineColor: rgba(102, 163, 224, 0.2);
  }

  .roots {
    width: 100%;
    height: 80vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
  }

  section {
    position: relative;
    width: 200px;
    height: 200px;
  }

  section::before {
    content: "";
    position: absolute;
    height: 10px;
    width: 10px;
    border-radius: 100%;
    border-top: 1px solid orange;
    top: 50%;
    left: 50%;
    margin-top: -5px;
    margin-left: -5px;
    animation: turn 1s infinite linear;
    filter: drop-shadow(0 0 2px var(--color)) drop-shadow(0 0 5px var(--color)) drop-shadow(0 0 10px var(--color)) drop-shadow(0 0 20px var(--color));
  }

  .box,
  .box::after,
  .box::before {
    border: 2px solid var(--lineColor);
    border-left: 2px solid var(--color);
    border-right: 2px solid var(--color);
    border-radius: 50%;
  }

  .box::after,
  .box::before {
    position: absolute;
    content: "";
    left: 50%;
    top: 50%;
  }

  .box {
    width: 200px;
    height: 200px;
    position: relative;
    animation: turn 1s linear infinite;
    transform-origin: 50% 50%;
  }

  .box::before {
    width: 180px;
    height: 180px;
    margin-top: -90px;
    margin-left: -90px;
    animation: turn2 1.25s linear infinite;
  }

  .box::after {
    width: 160px;
    height: 160px;
    margin-top: -80px;
    margin-left: -80px;
    animation: turn 1.5s linear infinite;
  }

  .box-circle,
  .box-circle1,
  .box-circle2 {
    border: 2px solid var(--color);
    opacity: 0.9;
    border-radius: 50%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform-origin: 50% 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 100px;
    animation: rotate 3s linear infinite;
  }

  .box-circle {
    animation-delay: 0.2s;
  }

  .box-circle1 {
    animation-delay: 1.2s;
  }

  .box-circle2 {
    animation-delay: 2.2s;
  }

  @keyframes turn {
    100% {
      transform: rotateZ(-1turn);
    }
  }

  @keyframes turn2 {
    100% {
      transform: rotateZ(1turn);
    }
  }

  @keyframes rotate {
    100% {
      border: none;
      border-top: 2px solid var(--color);
      border-bottom: 2px solid var(--color);
      transform: translate(-50%, -50%) rotate3d(0.5, 0.5, 0.5, -720deg);
    }
  }
}
</style>

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值