How To Use Custom Preloader In Vue.Js

Use Vue.js custom Preloader and it’s easily customizable also, without any npm plugin and without jquery.

 

Components 1: App.vue

Inside the src / App.vue file, Add the following elements.

<template>
    <div v-if="isLoading" class="preloader">
        <div class="d-table">
            <div class="d-table-cell">
                <div class="lds-spinner">
                    <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>

Step 2: Script

<script>
export default {
    name: 'App',
    data() {
        return {
            isLoading: true
        }
    },
    mounted() {
        setTimeout(() => {
            this.isLoading = false
        }, 2000)
    }
}
</script>

Step 3: SCSS

<style lang="scss" scoped>
.preloader {
    position: fixed;
    z-index: 999999;
    background-color: var(--white-color);
    width: 100%;
    height: 100%;
    text-align: center;
    left: 0;
    right: 0;

    .lds-spinner {
        color: official;
        display: inline-block;
        position: relative;
        width: 80px;
        height: 80px;

        div {
            transform-origin: 40px 40px;
            animation: lds-spinner 1.2s linear infinite;

            &::after {
                content: " ";
                display: block;
                position: absolute;
                top: 5px;
                left: 35px;
                width: 5px;
                height: 20px;
                border-radius: 20%;
                background: var(--main-color);
            }
            &:nth-child(1) {
                transform: rotate(0deg);
                animation-delay: -1.1s;
            }
            &:nth-child(2) {
                transform: rotate(30deg);
                animation-delay: -1s;
            }
            &:nth-child(3) {
                transform: rotate(60deg);
                animation-delay: -0.9s;
            }
            &:nth-child(4) {
                transform: rotate(90deg);
                animation-delay: -0.8s;
            }
            &:nth-child(5) {
                transform: rotate(120deg);
                animation-delay: -0.7s;
            }
            &:nth-child(6) {
                transform: rotate(150deg);
                animation-delay: -0.6s;
            }
            &:nth-child(7) {
                transform: rotate(180deg);
                animation-delay: -0.5s;
            }
            &:nth-child(8) {
                transform: rotate(210deg);
                animation-delay: -0.4s;
            }
            &:nth-child(9) {
                transform: rotate(240deg);
                animation-delay: -0.3s;
            }
            &:nth-child(10) {
                transform: rotate(270deg);
                animation-delay: -0.2s;
            }
            &:nth-child(11) {
                transform: rotate(300deg);
                animation-delay: -0.1s;
            }
            &:nth-child(12) {
                transform: rotate(330deg);
                animation-delay: 0s;
            }
        }
    }
    @keyframes lds-spinner {
        0% {
          opacity: 1;
        }
        100% {
          opacity: 0;
        }
    }
}
</style>

 

Leave a Reply

Your email address will not be published.