html+css制作简单loading动画

html+css制作简单loading动画

 <div class="loading">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </div>
body{
            height: 100vh;
            /* flex布局让盒子在主轴和中间轴居中,盒子就位于正中间 */
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .loading{
            position: relative;
            width: 190px;
            height: 190px;
            /* 让四个盒子grid布局 */
            display: grid;
            /* 设置二行二列的网格,并且列宽和行高都为80px */
            grid-template-columns: 80px 80px;
            grid-template-rows: 80px 80px;
            /* 间距为30px */
            gap: 30px;
            /* 每2s执行一次动画 */
            animation: rotate 2s infinite linear;
        }
        .loading div{
            /* 让div是圆形 */
            width: 80px;
            height: 80px;
            border-radius: 50%;
        }
        /* 设置每个div的颜色 */
        .loading div:nth-child(1){
            background-color:#19A68C ;
        }
        .loading div:nth-child(2){
            background-color:#F63D3A ;
        }
        .loading div:nth-child(3){
            background-color:#FDA543 ;
        }
        .loading div:nth-child(4){
            background-color:#193B48 ;
        }
        @keyframes rotate{
            /* 动画每10%转动45度,并且间距有变化 */
            0%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(0deg);
            }
            10%{
                width: 160px;
                height: 160px;
                gap: 0px;
                transform: rotate(45deg);
            }
            20%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(90deg);
            }
            /* 每90度停顿一下 */
            25%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(90deg);
            }
            35%{
                width: 160px;
                height: 160px;
                gap: 0px;
                transform: rotate(135deg);
            }
            45%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(180deg);
            }
            50%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(180deg);
            }
            60%{
                width: 160px;
                height: 160px;
                gap: 0px;
                transform: rotate(225deg);
            }
            70%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(270deg);
            }
            75%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(270deg);
            }
            85%{
                width: 160px;
                height: 160px;
                gap: 0px;
                transform: rotate(315deg);
            }
            95%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(360deg);
            }
            100%{
                width: 190px;
                height: 190px;
                gap: 30px;
                transform: rotate(360deg);
            }
        }

大概样子
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值