CSS加载动画效果

1. 分析元素
可以看到这个简单的特效由5个块通过延时差形成的,能给人一种再等等的想法。很不错,设计yyds。
5个块我们用5个盒子实现,配合CSS3的动画关键帧以及伪类选择器实现延时差即可实现。有一个好的分析和思路,可以减少你的coding出错率和time,🆗,coding吧!!!

2.html部分
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加载动画</title>
</head>
<body>
    <div class="box">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </div>
</body>
</html>

3.CSS部分

       .box{
            margin: 200px auto;
            width: 50px;
            height: 50px;
            text-align: center;
            font-size: 10px;
        }
        .box > div{
            background-color: rgba(64, 219, 25,0.9);
            width: 5px;
            height: 100%;
            /* 行内块 */
            display: inline-block;
            /*         名字  执行时间     一直执行       先慢再快再慢 */
            animation: move   1.2s      infinite    ease-in-out;

        }
        /* 定义关键帧 */
        @keyframes move{
            0%{transform: scaleY(0.4);}
            40%{transform: scaleY(0.4);}
            60%{transform: scaleY(0.4);}
            80%{transform: scaleY(0.4);}
            100%{transform: scaleY(0.4);}
            20%{transform: scaleY(1);}
        }
        /* 伪类选择器控制 匹配除了第一个以外的儿子,延时产生感觉*/
        .box>div:nth-child(2){
            animation-delay: -1s;
        }

        .box>div:nth-child(3){
            animation-delay: -0.9s;
        }
        .box>div:nth-child(4){
            animation-delay: -0.8s;
        }
        .box>div:nth-child(5){
            animation-delay: -0.7s;
        }
4.完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加载动画</title>
    <style>
        .box{
            margin: 200px auto;
            width: 50px;
            height: 50px;
            text-align: center;
            font-size: 10px;
        }
        .box > div{
            background-color: rgba(64, 219, 25,0.9);
            width: 5px;
            height: 100%;
            /* 行内块 */
            display: inline-block;
            /*         名字  执行时间     一直执行       先慢再快再慢 */
            animation: move   1.2s      infinite    ease-in-out;

        }
        /* 定义关键帧 */
        @keyframes move{
            0%{transform: scaleY(0.4);}
            40%{transform: scaleY(0.4);}
            60%{transform: scaleY(0.4);}
            80%{transform: scaleY(0.4);}
            100%{transform: scaleY(0.4);}
            20%{transform: scaleY(1);}
        }
        .box>div:nth-child(2){
            animation-delay: -1s;
        }
        .box>div:nth-child(3){
            animation-delay: -0.9s;
        }
        .box>div:nth-child(4){
            animation-delay: -0.8s;
        }
        .box>div:nth-child(5){
            animation-delay: -0.7s;
        }
    </style>
</head>
<body>
    <div class="box">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </div>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值