vue-loading模塊封裝(兼容移動(dòng)端)

vue-loading模塊封裝

封裝loading模塊

import '../loading-over/loading.css'

const doc = window.document
const $body = doc.body || doc.head
const $loading = doc.createElement('div')
$loading.classList.add('loader')
$loading.innerHTML = `<div class="logo">
                          <div class="white"></div>
                          <div class="orange"></div>
                          <div class="red"></div>
                      </div>`

const Loading = {
  show() {
    try {
      $body.appendChild($loading)
    } catch (e) {
    }
  },
  hide() {
    try {
      if ($loading.parentNode === $body) {
        $body.removeChild($loading)
      }
    } catch (e) {
    }
  }
}

export default Loading

router.js的設(shè)置(跳轉(zhuǎn)前,跳轉(zhuǎn)后)


router.beforeEach((to, from, next) => {
  loading.show()
  next()
})

router.afterEach(route => {
  loading.hide()
})
div.loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

div.loader-over {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

div.logo {
    width: 100px;
    height: 100px;
    box-sizing: border-box;
    position: relative;
}

div.logo::before,
div.logo::after {
    z-index: 1;
    box-sizing: border-box;
    content: '';
    position: absolute;
    border: 4px solid transparent;
    width: 0;
    height: 0;
    animation-direction: alternate;
    animation-timing-function: linear;
}

div.logo::before {
    top: 0;
    left: 0;
    animation: border-before 1.5s infinite;
    animation-direction: alternate;
}

div.logo::after {
    bottom: 0;
    right: 0;
    animation: border-after 1.5s infinite;
    animation-direction: alternate;
}

div.logo>div {
    position: absolute;
    opacity: 0;
}

div.logo div.white {
    border-left: 4px solid black;
    top: 0;
    bottom: 0;
    right: 0;
    width: 0;
    animation: white 1.5s infinite;
    animation-direction: alternate;
}

div.logo div.orange {
    border-top: 4px solid black;
    left: 0;
    bottom: 0;
    right: 0;
    height: 0;
    background-color: #F3B93F;
    animation: orange 1.5s infinite;
    animation-direction: alternate;
}

div.logo div.red {
    border-right: 4px solid black;
    top: 0;
    bottom: 0;
    left: 0;
    width: 0;
    background-color: #EA5664;
    animation: red 1.5s infinite;
    animation-direction: alternate;
}

@keyframes border-before {
    0% {
        width: 0;
        height: 0;
        border-top-color: black;
        border-right-color: transparent;
    }
    12.49% {
        border-right-color: transparent;
    }
    12.5% {
        height: 0;
        width: 100%;
        border-top-color: black;
        border-right-color: black;
    }
    25%,
    100% {
        width: 100%;
        height: 100%;
        border-top-color: black;
        border-right-color: black;
    }
}

@keyframes border-after {
    0%,
    24.99% {
        width: 0;
        height: 0;
        border-left-color: transparent;
        border-bottom-color: transparent;
    }
    25% {
        width: 0;
        height: 0;
        border-left-color: transparent;
        border-bottom-color: black;
    }
    37.49% {
        border-left-color: transparent;
        border-bottom-color: black;
    }
    37.5% {
        height: 0;
        width: 100%;
        border-left-color: black;
        border-bottom-color: black;
    }
    50%,
    100% {
        width: 100%;
        height: 100%;
        border-left-color: black;
        border-bottom-color: black;
    }
}

@keyframes red {
    0%,
    50% {
        width: 0;
        opacity: 0;
    }
    50.01% {
        opacity: 1;
    }
    65%,
    100% {
        opacity: 1;
        width: 27%;
    }
}

@keyframes orange {
    0%,
    65% {
        height: 0;
        opacity: 0;
    }
    65.01% {
        opacity: 1;
    }
    80%,
    100% {
        opacity: 1;
        height: 50%;
    }
}

@keyframes white {
    0%,
    75% {
        width: 0;
        opacity: 0;
    }
    75.01% {
        opacity: 1;
    }
    90%,
    100% {
        opacity: 1;
        width: 23%;
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容