欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CSS 的loading特效

程序员文章站 2022-07-14 10:44:28
...

之前做loading效果都是用的框架自带的,上周正好碰到需要,自己查了下资料,自己写了几个例子。

HTML的结构无非两种,第一自己写span结构;第二用伪元素模拟结构。

第一种:html结构

<div id="preloader_1">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </div>
css
#preloader_1{
            position: relative;
            left:50%;
            width:45px;
            height:30px;
        }
        #preloader_1 span{
            display: block;
            width:9px;
            height:5px;
            position: absolute;
            bottom:0;
            background: yellow;
            animation: preloader_1 1.5s infinite ease-in-out;
        }
        #preloader_1 span:nth-child(2){
            left:11px;
            animation-delay: .2s;
        }
        #preloader_1 span:nth-child(3){
            left:22px;
            animation-delay: .4s;
        }
        #preloader_1 span:nth-child(4){
            left:33px;
            animation-delay: .6s;
        }
        #preloader_1 span:nth-child(5){
            left:44px;
            animation-delay: .8s;
        }
        @keyframes preloader_1 {
            0% {height:5px;transform:translateY(0px);background:yellow;} 
            25% {height:30px;transform:translateY(15px);background:yellowgreen;}
            50% {height:5px;transform:translateY(0px);background:yellow;} 
            100% {height:5px;transform:translateY(0px);background:yellow;}

        }

效果图

CSS 的loading特效

第二种用伪元素模拟

html结构

  <div id="preloader_3">
        
    </div>

css结构

 #preloader_3{
            position: relative;
            left:50%;
            width:40px;
            height:40px;
        }
        #preloader_3:before{
            width:20px;
            height:20px;
            border-radius: 20px;
            background: tomato;
            content: '';
            position: absolute;
            animation: preloader_3_before 1.5s infinite ease-in-out;
        }
        #preloader_3:after{
            width:20px;
            height:20px;
            border-radius:20px;
            background:blue;
            content:''; 
            position:absolute;
            background:#2ecc71;
            left:22px;
            animation: preloader_3_after 1.5s infinite ease-in-out;
        }
        @keyframes preloader_3_before {
            0%{transform: translateX(0px) rotate(0deg)}
            50%{transform: translateX(50px) scale(1.2) rotate(260deg);background:#2ecc71; border-radius:0px;}
            100%{transform: translateX(0px) rotate(0deg)}
        }
        @keyframes preloader_3_after {
            0%{transform: translateX(0px) rotate(0deg)}
            50%{transform: translateX(-50px) scale(1.2) rotate(-260deg);background:#9b59b6; border-radius:0px;}
            100%{transform: translateX(0px) rotate(0deg)}
        }
效果图

CSS 的loading特效CSS 的loading特效


相关标签: loading