CSS加载动画效果

简介: 又是学习css和js的一天,在刷小视频加载时经常看到一些加载动画,简单上手了css3新增的动画后,就想仿写一个加载效果,就是玩哈哈,开整!

效果:


8de00778be3b4cfcabee66fb071b3ba5.gif


1. 分析元素



可以看到这个简单的特效由5个块通过延时差形成的,能给人一种再等等的想法。很不错,设计yyds。


5个块我们用5个盒子实现,配合CSS3的动画关键帧以及伪类选择器实现延时差即可实现。有一个好的分析和思路,可以减少你的coding出错率和time,🆗,coding吧!!!


2.html部分



这就是爸爸管着5个儿子,不用多说了


<!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部分



CSS3的结构伪类选择器控制 匹配除了第一个以外的儿子,延时产生感觉,哈哈,为啥不可以直接写在一个里好比.box>div:nth-child(2,3,4,5){ animation-delay: -1s; }不懂,可能还需要完善吧!我是这样想的


.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>


相关文章
|
1月前
|
前端开发 内存技术
CSS动画示例(上一篇是CSS过渡…)
CSS动画示例(上一篇是CSS过渡…)
22 1
|
1月前
|
资源调度 前端开发 CDN
纯css动画库animate.css的用法
纯css动画库animate.css的用法
46 0
|
2月前
CSS3滑动轮播动画
CSS3滑动轮播动画
33 8
|
3月前
|
前端开发
一个方便的小系统,用于 CSS 中的动画入口
一个方便的小系统,用于 CSS 中的动画入口
|
3月前
|
前端开发 JavaScript
前端必看的8个HTML+CSS技巧 (六) 裁剪图像的动画
前端必看的8个HTML+CSS技巧 (六) 裁剪图像的动画
|
18天前
|
前端开发
css3动画
css3动画
20 0
|
1月前
|
前端开发
CSS3中的动画示例
CSS3中的动画示例
12 1
|
1月前
|
前端开发
纯css实现的3D立体鸡蛋动画视觉效果
纯css实现的3D立体鸡蛋动画视觉效果
29 6
纯css实现的3D立体鸡蛋动画视觉效果
|
1月前
|
JavaScript
JS+CSS3点击粒子烟花动画js特效
JS+CSS3点击粒子烟花动画js特效
15 0
JS+CSS3点击粒子烟花动画js特效