纯css loading效果

117 阅读1分钟

60pzx-8gkir.gif

<style>
    #loading {
      --border-width: 5px;
      --size: 50px;
      width: var(--size);
      height: var(--size);
      border-radius: 100%;
      border-width: var(--border-width) var(--border-width) 0 0;
      border-style: solid;
      box-sizing: border-box;
      position: relative;
      border-color: #f7b64c transparent transparent;
      animation: round-loading 1s linear infinite;
    }

    #loading::after {
      --border-offset: calc(-1 * var(--border-width));
      content: '';
      position: absolute;
      left: 0;
      right: var(--border-offset);
      top: var(--border-offset);
      bottom: 0;
      border-radius: 100%;
      border-width: 0 0 var(--border-width) var(--border-width);
      border-style: solid;
      box-sizing: border-box;
      border-color: transparent transparent #f0885a;
    }

    @keyframes round-loading {
      100% {
        transform: rotateZ(360deg);
      }
    }
</style>

<div id="loading"></div>

w4g7f-2a5dg.gif

<style>
#loading-pot {
  --duration: 2s;
  width: 36px;
  height: 12px;
  border-radius: 0 0 12px 12px;
  background-color: black;
  position: relative;
  animation: rollup var(--duration) linear infinite;
}

#loading-pot::before {
  display: block;
  content: '';
  position: absolute;
  left: 102%;
  top: 1%;
  width: 20px;
  height: 5px;
  border-radius: 5px;
  background-color: black;
}

#loading-pot::after {
  position: absolute;
  content: '1';
  left: 50%;
  bottom: 0;
  transform: scale(0.1);
  font-size: 12px;
  font-weight: bold;
  text-shadow: 0.5px 0.5px black;
  animation: number-animation var(--duration) linear infinite, number-animation-2 var(--duration) cubic-bezier(0,.98,1,.99) infinite, number-animation-3 var(--duration) cubic-bezier(1,-0.01,1,.56) infinite;
}

@keyframes rollup {
  3% {
    transform: translate(-5px, -2px) rotateZ(-10deg);
  }
  20% {
    transform: rotateZ(-30deg) translate(-30px, -15px);
  }
  25% {
    transform: rotateZ(15deg) translate(-38px, -20px);
  }
  30% {
    transform: rotateZ(5deg) translate(-15px, -20px);
  }
  49% {
    transform: translateX(3px);
  }
  51% {
    transform: unset;
  }
}

@keyframes number-animation {
  20% {
    left: 3%;
  }
  50% {
    left: 80%;
  }
  51% {
    left: 50%;
  }
}
@keyframes number-animation-2 {
  20% {
    transform: scale(1) translateY(0) rotate(0deg);
  }
  35% {
    transform: translateY(-35px) rotate(-180deg);
  }
}
@keyframes number-animation-3 {
  35% {
    transform: translateY(-35px) rotate(-180deg);
  }
  50% {
    transform: translateY(0) rotate(180deg);
  }
  51% {
    transform: scale(0.1);
  }
}
</style>
<div id="loading-pot"></div>