封装一个loading渐变色svg

0 阅读2分钟
<template>
  <div class="loading-svg">
    <svg v-show="showCloseBtn" viewBox="0 0 84 24">
      <defs>
        <linearGradient id="yellowGradient" x1="0%" y1="0%" x2="100%" y2="0%">
          <stop offset="0%" style="stop-color: #ffa830; stop-opacity: 1" />
          <stop offset="100%" style="stop-color: #fd565d; stop-opacity: 1" />
        </linearGradient>
      </defs>
      <circle cx="18" cy="12" r="6" fill="url(#yellowGradient)"></circle>
      <circle cx="18" cy="12" r="6" fill="url(#yellowGradient)"></circle>
      <circle cx="42" cy="12" r="6" fill="url(#yellowGradient)"></circle>
      <circle cx="66" cy="12" r="6" fill="url(#yellowGradient)"></circle>
    </svg>
  </div>
</template>
<script setup lang="ts">
const showCloseBtn = ref(true)
const props = defineProps({
  color: {
    type: String,
    default: '#F44039'
  }
})
</script>
<style lang="less" scoped>
.loading-svg {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: fixed;
  z-index: 99;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
}
.loading-svg > svg {
  height: 40%;
  max-height: 34px;
  max-width: 80%;
  stroke: transparent;
}

.loading-svg circle {
  -webkit-transform-origin: center;
  -ms-transform-origin: center;
  transform-origin: center;
  will-change: transform;
  -webkit-animation-timing-function: linear;
  animation-timing-function: linear;
}

.loading-svg circle:nth-child(2) {
  -webkit-animation: lds-1-e1a15m3u 0.6s infinite;
  animation: lds-1-e1a15m3u 0.6s infinite;
}

.loading-svg circle:nth-child(3) {
  -webkit-animation: lds-2-e1a15m3u 0.6s infinite;
  animation: lds-2-e1a15m3u 0.6s infinite;
}

.loading-svg circle:nth-child(4) {
  -webkit-animation: lds-2-e1a15m3u 0.6s infinite;
  animation: lds-2-e1a15m3u 0.6s infinite;
}

.loading-svg circle:nth-child(5) {
  -webkit-animation: lds-3-e1a15m3u 0.6s infinite;
  animation: lds-3-e1a15m3u 0.6s infinite;
}

@-webkit-keyframes lds-1-e1a15m3u {
  0% {
    -webkit-transform: scale(0.4) translateX(28.57%);
    -ms-transform: scale(0.4) translateX(28.57%);
    transform: scale(0.4) translate(28.57%);
    opacity: 0.3;
  }

  to {
    -webkit-transform: scale(1) translateX(0%);
    -ms-transform: scale(1) translateX(0%);
    transform: scale(1) translate(0);
    opacity: 1;
  }
}

@keyframes lds-1-e1a15m3u {
  0% {
    -webkit-transform: scale(0.4) translateX(28.57%);
    -ms-transform: scale(0.4) translateX(28.57%);
    transform: scale(0.4) translate(28.57%);
    opacity: 0.3;
  }

  to {
    -webkit-transform: scale(1) translateX(0%);
    -ms-transform: scale(1) translateX(0%);
    transform: scale(1) translate(0);
    opacity: 1;
  }
}

@-webkit-keyframes lds-2-e1a15m3u {
  0% {
    -webkit-transform: translateX(0%);
    -ms-transform: translateX(0%);
    transform: translate(0);
  }

  to {
    -webkit-transform: translateX(28.57%);
    -ms-transform: translateX(28.57%);
    transform: translate(28.57%);
  }
}

@keyframes lds-2-e1a15m3u {
  0% {
    -webkit-transform: translateX(0%);
    -ms-transform: translateX(0%);
    transform: translate(0);
  }

  to {
    -webkit-transform: translateX(28.57%);
    -ms-transform: translateX(28.57%);
    transform: translate(28.57%);
  }
}

@-webkit-keyframes lds-3-e1a15m3u {
  0% {
    -webkit-transform: scale(1) translateX(0%);
    -ms-transform: scale(1) translateX(0%);
    transform: scale(1) translate(0);
    opacity: 1;
  }

  to {
    -webkit-transform: scale(0.4) translateX(-28.57%);
    -ms-transform: scale(0.4) translateX(-28.57%);
    transform: scale(0.4) translate(-28.57%);
    opacity: 0.3;
  }
}

@keyframes lds-3-e1a15m3u {
  0% {
    -webkit-transform: scale(1) translateX(0%);
    -ms-transform: scale(1) translateX(0%);
    transform: scale(1) translate(0);
    opacity: 1;
  }

  to {
    -webkit-transform: scale(0.4) translateX(-28.57%);
    -ms-transform: scale(0.4) translateX(-28.57%);
    transform: scale(0.4) translate(-28.57%);
    opacity: 0.3;
  }
}
</style>