常用loading加载效果集及vue实现加载动画

非常炫酷加载效果,大多都有=>:HTML5+CSS3 最酷的 loading 效果收集

加载效果1

在这里插入图片描述

代码

<style>
	$colors:
	  hsla(337, 84, 48, 0.75)
	  hsla(160, 50, 48, 0.75)
	  hsla(190, 61, 65, 0.75)
	  hsla( 41, 82, 52, 0.75);
	$size: 2.5em;
	$thickness: 0.5em;
	
	// Calculated variables.
	$lat: ($size - $thickness) / 2;
	$offset: $lat - $thickness;
	
	.loader {
      
      
	  position: relative;
	  width: $size;
	  height: $size;
	  transform: rotate(165deg);
	  
	  &:before,
	  &:after {
      
      
	    content: '';
	    position: absolute;
	    top: 50%;
	    left: 50%;
	    display: block;
	    width: $thickness;
	    height: $thickness;
	    border-radius: $thickness / 2;
	    transform: translate(-50%, -50%);
	  }
	  
	  &:before {
      
      
	    animation: before 2s infinite;
	  }
	  
	  &:after {
      
      
	    animation: after 2s infinite;
	  }
	}
	
	@keyframes before {
      
      
	  0% {
      
      
	    width: $thickness;
	    box-shadow:
	      $lat (-$offset) nth($colors, 1),
	      (-$lat) $offset nth($colors, 3);
	  }
	  35% {
      
      
	    width: $size;
	    box-shadow:
	      0 (-$offset) nth($colors, 1),
	      0   $offset  nth($colors, 3);
	  }
	  70% {
      
      
	    width: $thickness;
	    box-shadow:
	      (-$lat) (-$offset) nth($colors, 1),
	      $lat $offset nth($colors, 3);
	  }
	  100% {
      
      
	    box-shadow:
	      $lat (-$offset) nth($colors, 1),
	      (-$lat) $offset nth($colors, 3);
	  }
	}
	
	@keyframes after {
      
      
	  0% {
      
      
	    height: $thickness;
	    box-shadow:
	      $offset $lat nth($colors, 2),
	      (-$offset) (-$lat) nth($colors, 4);
	  }
	  35% {
      
      
	    height: $size;
	    box-shadow:
	        $offset  0 nth($colors, 2),
	      (-$offset) 0 nth($colors, 4);
	  }
	  70% {
      
      
	    height: $thickness;
	    box-shadow:
	      $offset (-$lat) nth($colors, 2),
	      (-$offset) $lat nth($colors, 4);
	  }
	  100% {
      
      
	    box-shadow:
	      $offset $lat nth($colors, 2),
	      (-$offset) (-$lat) nth($colors, 4);
	  }
	}
	
	
	
	/**
	 * Attempt to center the whole thing!
	 */
	
	html,
	body {
      
      
	  height: 100%;
	}
	
	.loader {
      
      
	  position: absolute;
	  top: calc(50% - #{
      
      $size / 2});
	  left: calc(50% - #{
      
      $size / 2});
	}
</style>

<div class="loader"></div>

加载效果2

在这里插入图片描述

代码

<style>
	.loader {
      
      
	    background: #000;
	    background: radial-gradient(#222, #000);
	    bottom: 0;
	    left: 0;
	    overflow: hidden;
	    position: fixed;
	    right: 0;
	    top: 0;
	    z-index: 99999;
	}
	
	.loader-inner {
      
      
	    bottom: 0;
	    height: 60px;
	    left: 0;
	    margin: auto;
	    position: absolute;
	    right: 0;
	    top: 0;
	    width: 100px;
	}
	
	.loader-line-wrap {
      
      
	    animation:
	        spin 2000ms cubic-bezier(.175, .885, .32, 1.275) infinite;
	    box-sizing: border-box;
	    height: 50px;
	    left: 0;
	    overflow: hidden;
	    position: absolute;
	    top: 0;
	    transform-origin: 50% 100%;
	    width: 100px;
	}
	
	.loader-line {
      
      
	    border: 4px solid transparent;
	    border-radius: 100%;
	    box-sizing: border-box;
	    height: 100px;
	    left: 0;
	    margin: 0 auto;
	    position: absolute;
	    right: 0;
	    top: 0;
	    width: 100px;
	}
	
	.loader-line-wrap:nth-child(1) {
      
      
	    animation-delay: -50ms;
	}
	
	.loader-line-wrap:nth-child(2) {
      
      
	    animation-delay: -100ms;
	}
	
	.loader-line-wrap:nth-child(3) {
      
      
	    animation-delay: -150ms;
	}
	
	.loader-line-wrap:nth-child(4) {
      
      
	    animation-delay: -200ms;
	}
	
	.loader-line-wrap:nth-child(5) {
      
      
	    animation-delay: -250ms;
	}
	
	.loader-line-wrap:nth-child(1) .loader-line {
      
      
	    border-color: hsl(0, 80%, 60%);
	    height: 90px;
	    width: 90px;
	    top: 7px;
	}
	
	.loader-line-wrap:nth-child(2) .loader-line {
      
      
	    border-color: hsl(60, 80%, 60%);
	    height: 76px;
	    width: 76px;
	    top: 14px;
	}
	
	.loader-line-wrap:nth-child(3) .loader-line {
      
      
	    border-color: hsl(120, 80%, 60%);
	    height: 62px;
	    width: 62px;
	    top: 21px;
	}
	
	.loader-line-wrap:nth-child(4) .loader-line {
      
      
	    border-color: hsl(180, 80%, 60%);
	    height: 48px;
	    width: 48px;
	    top: 28px;
	}
	
	.loader-line-wrap:nth-child(5) .loader-line {
      
      
	    border-color: hsl(240, 80%, 60%);
	    height: 34px;
	    width: 34px;
	    top: 35px;
	}
	
	@keyframes spin {
      
      
	
	    0%,
	    15% {
      
      
	        transform: rotate(0);
	    }
	
	    100% {
      
      
	        transform: rotate(360deg);
	    }
	}
</style>
<div class="loader">
    <div class="loader-inner">
        <div class="loader-line-wrap">
            <div class="loader-line"></div>
        </div>
        <div class="loader-line-wrap">
            <div class="loader-line"></div>
        </div>
        <div class="loader-line-wrap">
            <div class="loader-line"></div>
        </div>
        <div class="loader-line-wrap">
            <div class="loader-line"></div>
        </div>
        <div class="loader-line-wrap">
            <div class="loader-line"></div>
        </div>
    </div>
</div>

加载效果3

在这里插入图片描述

代码

<style>
	.sk-chase {
      
      
	  width: 40px;
	  height: 40px;
	  position: relative;
	  animation: sk-chase 2.5s infinite linear both;
	}
	
	.sk-chase-dot {
      
      
	  width: 100%;
	  height: 100%;
	  position: absolute;
	  left: 0;
	  top: 0; 
	  animation: sk-chase-dot 2.0s infinite ease-in-out both; 
	}
	
	.sk-chase-dot:before {
      
      
	  content: '';
	  display: block;
	  width: 25%;
	  height: 25%;
	  background-color: #fff;
	  border-radius: 100%;
	  animation: sk-chase-dot-before 2.0s infinite ease-in-out both; 
	}
	
	.sk-chase-dot:nth-child(1) {
      
       animation-delay: -1.1s; }
	.sk-chase-dot:nth-child(2) {
      
       animation-delay: -1.0s; }
	.sk-chase-dot:nth-child(3) {
      
       animation-delay: -0.9s; }
	.sk-chase-dot:nth-child(4) {
      
       animation-delay: -0.8s; }
	.sk-chase-dot:nth-child(5) {
      
       animation-delay: -0.7s; }
	.sk-chase-dot:nth-child(6) {
      
       animation-delay: -0.6s; }
	.sk-chase-dot:nth-child(1):before {
      
       animation-delay: -1.1s; }
	.sk-chase-dot:nth-child(2):before {
      
       animation-delay: -1.0s; }
	.sk-chase-dot:nth-child(3):before {
      
       animation-delay: -0.9s; }
	.sk-chase-dot:nth-child(4):before {
      
       animation-delay: -0.8s; }
	.sk-chase-dot:nth-child(5):before {
      
       animation-delay: -0.7s; }
	.sk-chase-dot:nth-child(6):before {
      
       animation-delay: -0.6s; }
	
	@keyframes sk-chase {
      
      
	  100% {
      
       transform: rotate(360deg); } 
	}
	
	@keyframes sk-chase-dot {
      
      
	  80%, 100% {
      
       transform: rotate(360deg); } 
	}
	
	@keyframes sk-chase-dot-before {
      
      
	  50% {
      
      
	    transform: scale(0.4); 
	  } 100%, 0% {
      
      
	    transform: scale(1.0); 
	  } 
	}
</style>

<div style="position:fixed;left:0;top:0;display:flex;align-items: center;justify-content: center;;width:100%;height: 100%;background-color: #000;">
    <div class="sk-chase">
        <div class="sk-chase-dot"></div>
        <div class="sk-chase-dot"></div>
        <div class="sk-chase-dot"></div>
        <div class="sk-chase-dot"></div>
        <div class="sk-chase-dot"></div>
        <div class="sk-chase-dot"></div>
    </div>
</div>

下面自己动手实现一个吧

在这里插入图片描述
思路:只需要先把loading的盒子摆在正中间,然后,里面的每个item都使用绝对定位,并且水平垂直居中,然后先旋转,再位移,就可以呈现一个环状,接着指定动画,并设置延迟即可。(其实,下边并不需要给loading指定大小,这样就不用设置上下左右都是0,margin是auto了)

<style lang="scss">
    body {
      
      
        margin: 0;
    }
    .modal {
      
      
        background: #202020;
        height: 100vh;
        width: 100vw;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .loading {
      
      
        position: relative;
        width: 50px;
        height: 50px;
        div {
      
      
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            position: absolute;
            width: 5px;
            height: 20px;
            border-radius: 5px;
            background-color: #ff7300;
            animation: loading-spin 1s infinite;
        }
    }
    @keyframes loading-spin {
      
      
        0% {
      
      
            opacity: 0;
        }
        100% {
      
      
            opacity: 1;
        }
    }
    .loading .item1 {
      
      
        transform: rotate(30deg) translate(0,-120%);
        animation-delay: 1.1s;

    }
    .loading .item2 {
      
      
        transform: rotate(60deg) translate(0,-120%);
        animation-delay: 1s;
    }
    .loading .item3 {
      
      
        transform: rotate(90deg) translate(0,-120%);
        animation-delay: 0.9s;

    }
    .loading .item4 {
      
      
        transform: rotate(120deg) translate(0,-120%);
        animation-delay: 0.8s;

    }
    
    .loading .item5 {
      
      
        transform: rotate(150deg) translate(0,-120%);
        animation-delay: 0.7s;

    }
    .loading .item6 {
      
      
        transform: rotate(180deg) translate(0,-120%);
        animation-delay: 0.6s;
    }
    .loading .item7 {
      
      
        transform: rotate(210deg) translate(0,-120%);
        animation-delay: 0.5s;
    }
    .loading .item8 {
      
      
        transform: rotate(240deg) translate(0,-120%);
        animation-delay: 0.4s;

    }
    .loading .item9 {
      
      
        transform: rotate(270deg) translate(0,-120%);
        animation-delay: 0.3s;

    }
    .loading .item10 {
      
      
        transform: rotate(300deg) translate(0,-120%);
        animation-delay: 0.2s;

    }
    .loading .item11 {
      
      
        transform: rotate(330deg) translate(0,-120%);
        animation-delay: 0.1s;

    }
    .loading .item12 {
      
      
        transform: rotate(360deg) translate(0,-120%);
        animation-delay: 0s;

    } 
</style>
<template>
    <div class="modal">
        <div class="loading">
            <div class="item1"></div>
            <div class="item2"></div>
            <div class="item3"></div>
            <div class="item4"></div>
            <div class="item5"></div>
            <div class="item6"></div>
            <div class="item7"></div>
            <div class="item8"></div>
            <div class="item9"></div>
            <div class="item10"></div>
            <div class="item11"></div>
            <div class="item12"></div>
        </div>
    </div>
</template>

<script>

export default {
      
      
    name: 'loading',
    components: {
      
      
    }
}
</script>


猜你喜欢

转载自blog.csdn.net/qq_16992475/article/details/129809008