WD1X.COM - 问答一下,轻松解决,电脑应用解决专家
主板显卡CPU内存显示器
硬盘维修显卡维修显示器维修
注册表系统命令DOS命令Win8
存储光存储鼠标键盘
内存维修打印机维修
WinXPWin7Win11Linux
硬件综合机箱电源散热器手机数码
主板维修CPU维修键盘鼠标维修
Word教程Excel教程PowerPointWPS
网络工具系统工具图像工具
数据库javascript服务器
PHP教程CSS教程XML教程

音波加载效果 html+css

更新时间:2021-04-16 09:26 作者:北极光之夜点击:
先看效果╰(●◡●)╮(完整代码在底部):
实例演示地址:http://www.wd1x.com/css/canvas4.html
这个是比较常见的一个简约效果,拿下~
 
实现(可一步一步实现):
 
0.基本css样式(复制即可)* :
 
*{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: rgb(4, 6, 17);
        }
 
1.先定义标签(详解):
 
<div class="container">
        <span style="--i:1;"></span>
        <span style="--i:2;"></span>
        <span style="--i:3;"></span>
        <span style="--i:4;"></span>
        <span style="--i:5;"></span>
        <span style="--i:6;"></span>
        <span style="--i:7;"></span>
        <span style="--i:8;"></span>
        <span style="--i:9;"></span>
        <span style="--i:10;"></span>
    </div>
 
.container就是底层盒子,span就是每个圈。
"- -i:1;"是css的var函数的运用,点这看用法~
 
2.底层盒子基本样式:
 
.container{
            position: relative;
            width: 20px;
            height: 20px;
            transform-style: preserve-3d;
            transform: perspective(500px) rotateX(50deg) translateZ(50px);
        }
 
position:relative 相对定位。
transform-style:preserve-3d 子元素获得3D位置。
perspective:元素距离视图的距离,以像素计。
rotateX(50deg) 绕X轴旋转50度。
translateZ(50px); 往Z轴偏移50px。
 
2.每个圆圈的css样式,设置动画:
 
.container span{
            position: absolute;
            top: calc(-9px * var(--i));
            left: calc(-9px * var(--i));
            bottom: calc(-9px * var(--i));
            right: calc(-9px * var(--i));
            border: 5px solid rgba(0, 162, 255,0.8);
            box-shadow: 0 6px 0 rgb(0, 162, 255),
            inset 0 6px 0 rgba(0, 162, 255,.9);
            /* background-color: rgba(0, 162, 255,0); */
            border-radius: 50%;
            animation: move 1.5s ease-in-out infinite alternate;
            animation-delay: calc(var(--i) * 0.1s);
        }
        @keyframes move{
            0%,100%{
                transform: translateZ(0px);
            }
            50%{
               transform: translateZ(-100px);
            }
        }
 
position: absolute; 绝对定位。
calc() 函数用于动态计算长度值。
top: calc(-9px * var(- -i));
left: calc(-9px * var(- -i));
bottom: calc(-9px * var(- -i));
right: calc(-9px * var(- -i)); 通过calc()计算每个圈的大小。
border: 5px solid rgba(0, 162, 255,0.8); 蓝色边框。
box-shadow: 0 6px 0 rgb(0, 162, 255),
inset 0 6px 0 rgba(0, 162, 255,.9); 阴影。一个外阴影,一个内阴影。目的是为了让圆圈有点立体效果。
border-radius: 50%; 角弧度。
animation: move 1.5s ease-in-out infinite alternate; 定义动画。
animation-delay: calc(var(–i) * 0.1s); 通过calc()计算每个圈延迟多久后执行动画。
transform: translateZ(0px); Z轴方向的偏移。
 
完整代码♪(^∀^●)ノ:

 
<!DOCTYPE html>
<html lang="zh-CN">
<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>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: rgb(4, 6, 17);
        }
        .container{
            position: relative;
            width: 20px;
            height: 20px;
            transform-style: preserve-3d;
            transform: perspective(500px) rotateX(50deg) translateZ(50px);
        }
        .container span{
            position: absolute;
            top: calc(-9px * var(--i));
            left: calc(-9px * var(--i));
            bottom: calc(-9px * var(--i));
            right: calc(-9px * var(--i));
            border: 5px solid rgba(0, 162, 255,0.8);
            box-shadow: 0 6px 0 rgb(0, 162, 255),
            inset 0 6px 0 rgba(0, 162, 255,.9);
            /* background-color: rgba(0, 162, 255,0); */
            border-radius: 50%;
            animation: move 1.5s ease-in-out infinite alternate;
            animation-delay: calc(var(--i) * 0.1s);
        }
        @keyframes move{
            0%,100%{
                transform: translateZ(0px);
            }
            50%{
               transform: translateZ(-100px);
            }
        }
       
    </style>
</head>
<body>
    <div class="container">
        <span style="--i:1;"></span>
        <span style="--i:2;"></span>
        <span style="--i:3;"></span>
        <span style="--i:4;"></span>
        <span style="--i:5;"></span>
        <span style="--i:6;"></span>
        <span style="--i:7;"></span>
        <span style="--i:8;"></span>
        <span style="--i:9;"></span>
        <span style="--i:10;"></span>
    </div>
</body>
</html>
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
你可能感兴趣的内容