纯css加载指示器-仿苹果

html结构

<div class="loading">
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>
  <div><div></div></div>  
</div>

scss

@for $i from 0 through 12 {
  @keyframes opacity-60-25-#{$i}-13 {
    0% {
      opacity: if($i <= 5, 0.25, ($i - 5)*0.09 + 1/3);
    }
    #{(1/13 * $i +0.001) * 100%} {
      opacity: 0.25;
    }
    #{(1/13 * $i +0.002) * 100%} {
      opacity: 1;
    }
    #{(1/13 * $i +0.001) * 100%} {
      opacity: 0.25;
    }
    100% {
      opacity: if($i <= 5, 0.25, ($i - 5)*0.09 + 1/3);
    }
  }
}
.loading{
  position: absolute;
  width: 0px;
  z-index: 2000000000;
  left: 50%;
  top: 50%;
  @for $i from 0 through 12{
    >div:nth-child(#{$i + 1}){
      position: absolute;
      top: -1px;
      opacity: 0.25;
      animation: opacity-60-25-#{$i}-13 1s linear 0s infinite normal none running;
      div{
        position: absolute;
        width: 8.5px;
        height: 2.25px;
        background: rgb(0, 0, 0);
        box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
        transform-origin: left center 0px;
        transform: rotate(#{$i*360/13}deg) translate(5px, 0px);
        border-radius: 1px;
      }
    }
  }
}

编译后css

@-webkit-keyframes opacity-60-25-0-13 {
  0% {
    opacity: 0.25;
  }
  0.1% {
    opacity: 0.25;
  }
  0.2% {
    opacity: 1;
  }
  0.1% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@keyframes opacity-60-25-0-13 {
  0% {
    opacity: 0.25;
  }
  0.1% {
    opacity: 0.25;
  }
  0.2% {
    opacity: 1;
  }
  0.1% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@-webkit-keyframes opacity-60-25-1-13 {
  0% {
    opacity: 0.25;
  }
  7.7923076923% {
    opacity: 0.25;
  }
  7.8923076923% {
    opacity: 1;
  }
  7.7923076923% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@keyframes opacity-60-25-1-13 {
  0% {
    opacity: 0.25;
  }
  7.7923076923% {
    opacity: 0.25;
  }
  7.8923076923% {
    opacity: 1;
  }
  7.7923076923% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@-webkit-keyframes opacity-60-25-2-13 {
  0% {
    opacity: 0.25;
  }
  15.4846153846% {
    opacity: 0.25;
  }
  15.5846153846% {
    opacity: 1;
  }
  15.4846153846% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@keyframes opacity-60-25-2-13 {
  0% {
    opacity: 0.25;
  }
  15.4846153846% {
    opacity: 0.25;
  }
  15.5846153846% {
    opacity: 1;
  }
  15.4846153846% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@-webkit-keyframes opacity-60-25-3-13 {
  0% {
    opacity: 0.25;
  }
  23.1769230769% {
    opacity: 0.25;
  }
  23.2769230769% {
    opacity: 1;
  }
  23.1769230769% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@keyframes opacity-60-25-3-13 {
  0% {
    opacity: 0.25;
  }
  23.1769230769% {
    opacity: 0.25;
  }
  23.2769230769% {
    opacity: 1;
  }
  23.1769230769% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@-webkit-keyframes opacity-60-25-4-13 {
  0% {
    opacity: 0.25;
  }
  30.8692307692% {
    opacity: 0.25;
  }
  30.9692307692% {
    opacity: 1;
  }
  30.8692307692% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@keyframes opacity-60-25-4-13 {
  0% {
    opacity: 0.25;
  }
  30.8692307692% {
    opacity: 0.25;
  }
  30.9692307692% {
    opacity: 1;
  }
  30.8692307692% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@-webkit-keyframes opacity-60-25-5-13 {
  0% {
    opacity: 0.25;
  }
  38.5615384615% {
    opacity: 0.25;
  }
  38.6615384615% {
    opacity: 1;
  }
  38.5615384615% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@keyframes opacity-60-25-5-13 {
  0% {
    opacity: 0.25;
  }
  38.5615384615% {
    opacity: 0.25;
  }
  38.6615384615% {
    opacity: 1;
  }
  38.5615384615% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.25;
  }
}
@-webkit-keyframes opacity-60-25-6-13 {
  0% {
    opacity: 0.4233333333;
  }
  46.2538461538% {
    opacity: 0.25;
  }
  46.3538461538% {
    opacity: 1;
  }
  46.2538461538% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.4233333333;
  }
}
@keyframes opacity-60-25-6-13 {
  0% {
    opacity: 0.4233333333;
  }
  46.2538461538% {
    opacity: 0.25;
  }
  46.3538461538% {
    opacity: 1;
  }
  46.2538461538% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.4233333333;
  }
}
@-webkit-keyframes opacity-60-25-7-13 {
  0% {
    opacity: 0.5133333333;
  }
  53.9461538462% {
    opacity: 0.25;
  }
  54.0461538462% {
    opacity: 1;
  }
  53.9461538462% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.5133333333;
  }
}
@keyframes opacity-60-25-7-13 {
  0% {
    opacity: 0.5133333333;
  }
  53.9461538462% {
    opacity: 0.25;
  }
  54.0461538462% {
    opacity: 1;
  }
  53.9461538462% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.5133333333;
  }
}
@-webkit-keyframes opacity-60-25-8-13 {
  0% {
    opacity: 0.6033333333;
  }
  61.6384615385% {
    opacity: 0.25;
  }
  61.7384615385% {
    opacity: 1;
  }
  61.6384615385% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.6033333333;
  }
}
@keyframes opacity-60-25-8-13 {
  0% {
    opacity: 0.6033333333;
  }
  61.6384615385% {
    opacity: 0.25;
  }
  61.7384615385% {
    opacity: 1;
  }
  61.6384615385% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.6033333333;
  }
}
@-webkit-keyframes opacity-60-25-9-13 {
  0% {
    opacity: 0.6933333333;
  }
  69.3307692308% {
    opacity: 0.25;
  }
  69.4307692308% {
    opacity: 1;
  }
  69.3307692308% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.6933333333;
  }
}
@keyframes opacity-60-25-9-13 {
  0% {
    opacity: 0.6933333333;
  }
  69.3307692308% {
    opacity: 0.25;
  }
  69.4307692308% {
    opacity: 1;
  }
  69.3307692308% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.6933333333;
  }
}
@-webkit-keyframes opacity-60-25-10-13 {
  0% {
    opacity: 0.7833333333;
  }
  77.0230769231% {
    opacity: 0.25;
  }
  77.1230769231% {
    opacity: 1;
  }
  77.0230769231% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.7833333333;
  }
}
@keyframes opacity-60-25-10-13 {
  0% {
    opacity: 0.7833333333;
  }
  77.0230769231% {
    opacity: 0.25;
  }
  77.1230769231% {
    opacity: 1;
  }
  77.0230769231% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.7833333333;
  }
}
@-webkit-keyframes opacity-60-25-11-13 {
  0% {
    opacity: 0.8733333333;
  }
  84.7153846154% {
    opacity: 0.25;
  }
  84.8153846154% {
    opacity: 1;
  }
  84.7153846154% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.8733333333;
  }
}
@keyframes opacity-60-25-11-13 {
  0% {
    opacity: 0.8733333333;
  }
  84.7153846154% {
    opacity: 0.25;
  }
  84.8153846154% {
    opacity: 1;
  }
  84.7153846154% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.8733333333;
  }
}
@-webkit-keyframes opacity-60-25-12-13 {
  0% {
    opacity: 0.9633333333;
  }
  92.4076923077% {
    opacity: 0.25;
  }
  92.5076923077% {
    opacity: 1;
  }
  92.4076923077% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.9633333333;
  }
}
@keyframes opacity-60-25-12-13 {
  0% {
    opacity: 0.9633333333;
  }
  92.4076923077% {
    opacity: 0.25;
  }
  92.5076923077% {
    opacity: 1;
  }
  92.4076923077% {
    opacity: 0.25;
  }
  100% {
    opacity: 0.9633333333;
  }
}
.loading {
  position: absolute;
  width: 0px;
  z-index: 2000000000;
  left: 50%;
  top: 50%;
}
.loading > div:nth-child(1) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-0-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-0-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(1) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(0deg) translate(5px, 0px);
          transform: rotate(0deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(2) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-1-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-1-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(2) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(27.6923076923deg) translate(5px, 0px);
          transform: rotate(27.6923076923deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(3) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-2-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-2-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(3) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(55.3846153846deg) translate(5px, 0px);
          transform: rotate(55.3846153846deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(4) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-3-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-3-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(4) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(83.0769230769deg) translate(5px, 0px);
          transform: rotate(83.0769230769deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(5) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-4-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-4-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(5) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(110.7692307692deg) translate(5px, 0px);
          transform: rotate(110.7692307692deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(6) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-5-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-5-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(6) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(138.4615384615deg) translate(5px, 0px);
          transform: rotate(138.4615384615deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(7) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-6-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-6-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(7) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(166.1538461538deg) translate(5px, 0px);
          transform: rotate(166.1538461538deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(8) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-7-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-7-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(8) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(193.8461538462deg) translate(5px, 0px);
          transform: rotate(193.8461538462deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(9) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-8-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-8-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(9) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(221.5384615385deg) translate(5px, 0px);
          transform: rotate(221.5384615385deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(10) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-9-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-9-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(10) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(249.2307692308deg) translate(5px, 0px);
          transform: rotate(249.2307692308deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(11) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-10-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-10-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(11) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(276.9230769231deg) translate(5px, 0px);
          transform: rotate(276.9230769231deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(12) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-11-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-11-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(12) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(304.6153846154deg) translate(5px, 0px);
          transform: rotate(304.6153846154deg) translate(5px, 0px);
  border-radius: 1px;
}
.loading > div:nth-child(13) {
  position: absolute;
  top: -1px;
  opacity: 0.25;
  -webkit-animation: opacity-60-25-12-13 1s linear 0s infinite normal none running;
          animation: opacity-60-25-12-13 1s linear 0s infinite normal none running;
}
.loading > div:nth-child(13) div {
  position: absolute;
  width: 8.5px;
  height: 2.25px;
  background: black;
  -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
          box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1px;
  -webkit-transform-origin: left center 0px;
          transform-origin: left center 0px;
  -webkit-transform: rotate(332.3076923077deg) translate(5px, 0px);
          transform: rotate(332.3076923077deg) translate(5px, 0px);
  border-radius: 1px;
}

自定义Vue加载组件

<template>
    <div class="loading-template">
        <div class="loading" v-show="isShow">
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
            <div><div></div></div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Loading",
        data() {
            return {
                isShow:false
            }
        },
        methods:{
            showLoad(){
                this.isShow = true;
                this.promise = new Promise((resolve, reject) => {
                    this.resolve = resolve;
                    this.reject = reject;
                });
                return this.promise;
            },
            hideLoad() {
                setTimeout(() => {
                    this.destroy();
                }, 300);
            },
            destroy() {
                this.$destroy();
                document.body.removeChild(this.$el);
            }
        }
    }
</script>
import loadingTemplate from './components/Loading'
let Loading = {
    install:function(Vue, options){
        const LoadingInit = Vue.extend(loadingTemplate);
        let currentLoad;
        const initInstance = () => {
            // 实例化vue实例
            currentLoad = new LoadingInit();
            let msgBoxEl = currentLoad.$mount().$el;
            document.body.appendChild(msgBoxEl);
        };
        Vue.prototype.$loading = {
            show(options){
                if(!currentLoad){
                    initInstance();
                }
                if(Object.prototype.toString.call(options) === "[object Object]"){
                    Object.asign(currentLoad,options);
                }
                return currentLoad.showLoad()
                    .then(val=>{
                        currentLoad = null;
                        return Promise.resolve();
                    })
                    .catch(err=>{
                        currentLoad = null;
                        return Promise.reject();
                    })
            },
            hide(){
                if(currentLoad){
                    currentLoad.hideLoad();
                    currentLoad = null;
                }
            }
        }
    }
}
export default Loading

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值