大家好,我是 Just,这里是「设计师工作日常」,今天分享的是使用 css 实现一个动态的雷达扫描,快学起来吧!
最新文章通过公众号「设计师工作日常」发布。
目录
整体效果
知识点:
①animation
动画属性中animation-direction
以及steps()
参数的使用
思路: 先绘制出整体大圆,然后使用创建伪元素画出内里的小圆,并加上虚线边框;然后绘制出雷达层,加上动画旋转;再给雷达内增加几个闪烁的圆点;最后外层套一个小动画边框。
核心代码部分,简要说明了写法思路;完整代码在最后,可直接复制到本地运行。
核心代码
html 代码
雷达的主体。
css 部分代码
.leidabox50{
width:220px;
height:220px;
border:4px solid rgba(0,0,0,0);
border-top-color: #33B589;
border-bottom-color: #33B589;
border-radius:50%;
position: absolute;
animation:leidabox-eff-50 10s linear infinite;
animation-direction:reverse;
}
@keyframes leidabox-eff-50{
to{
transform:rotate(360deg);
}
}
.leida50{
width: 200px;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
background-color: #31FFBA;
border-radius: 50%;
border: 1px solid #33B589;
}
.leida50:before,.leida50:after{
content: '';
width: 120px;
height: 120px;
border-radius: 50%;
border: 1px dashed rgba(0,0,0,0.14);
box-shadow: 0 0 20px rgba(0,0,0,0.1);
position: absolute;
z-index: 3;
}
.leida50:after{
width: 60px;
height: 60px;
position: absolute;
z-index: 10;
}
.line50{
width: 100px;
height: 100px;
background-color: rgba(127,255,212,0.4);
border-radius: 0 0 0 100%;
position: absolute;
left: 0;
top: 100px;
z-index: 100;
animation: zhuaneff50 5s linear infinite;
transform-origin: 100px 0;
}
.line50:after{
content: '';
width: 8px;
height: 8px;
background-color: rgba(255,255,255,0.6);
position: absolute;
top: -4px;
right: -4px;
border-radius: 50%;
}
@keyframes zhuaneff50{
to {
transform: rotate(360deg);
}
}
.guangdian50{
position: absolute;
bottom: 66px;
}
.dian50,.dian50:after,.dian50:before{
width: 7px;
height: 7px;
background-color: #33B589;
position: absolute;
left: -20px;
border-radius: 50%;
animation: eff50 5s steps(6) infinite;
z-index: 999;
}
.dian50:after{
content: '';
width: 6px;
height: 6px;
top: 12px;
left: 44px;
}
.dian50:before{
content: '';
width: 3px;
height: 3px;
top: 40px;
left: 34px;
}
@keyframes eff50{
0% {
opacity: 0;
transform: translate(0, 0);
}
25%{
opacity: 1;
transform: translate(-10px, -18px);
}
50%{
opacity: 0;
transform: translate(-18px, -20px);
}
75%{
opacity: 1;
transform: translate(-24px, -18px);
}
100%{
opacity: 0;
transform: translate(-34px, -24px);
}
}
.guangdian50:after,.guangdian50:before{
content: '';
width: 6px;
height: 6px;
background-color: #33B589;
position: absolute;
top: -100px;
left: 30px;
border-radius: 50%;
z-index: 900;
animation: eff501 5s steps(6) both infinite;
}
.guangdian50:before{
width: 7px;
height: 7px;
top: -20px;
left: 40px;
}
@keyframes eff501{
0% {
opacity: 0;
}
25%{
opacity: 1;
}
50%{
opacity: 0;
}
75%{
opacity: 1;
}
100%{
opacity: 0;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
1、
.leida50
画出最大的雷达圆形主体,然后通过.leida50:before
和.leida50:after
伪元素创建里面的两个小圆,并给两个小圆加上一点阴影效果。
2、
.line50
绘制一个矩形,并给它的一个角加上圆角border-radius: 0 0 0 100%;
,并通过transform-origin
定位其原点,加上动画旋转,雷达就开始旋转扫描了; 然后
利用.line50:after
伪元素给中心加上一个固定点,这样整体的雷达扫描区就完成了。
3、再在雷达主体上绘制几个移动的点,利用
.dian50
、.dian50:after
和.dian50:before
绘制 3 个大小不一的圆点,并且定位到不同的位置,然后通过加上animation
动画,设置steps()
参数,使这 3 个点边闪烁边移动。
4、然后再加上两个固定的圆点,同样加上
animation
动画,设置steps()
参数,让这 2 个圆点同前面的 3 个圆点同时闪烁。
5、在外层用
.leidabox50
绘制出两个半边框,加上animation
动画,并设置animation-direction
参数,使反向旋转。
完整代码如下
html 页面
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>动态雷达扫描</title>
</head>
<body>
<div class="app">
<div class="leidabox50"></div>
<div class="leida50">
<div class="line50"></div>
<div class="guangdian50">
<span class="dian50"></span>
</div>
</div>
</div>
</body>
</html>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
css 样式
/** style.css **/
.app{
width: 100%;
height: 100vh;
background-color: #ffffff;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.leidabox50{
width:220px;
height:220px;
border:4px solid rgba(0,0,0,0);
border-top-color: #33B589;
border-bottom-color: #33B589;
border-radius:50%;
position: absolute;
animation:leidabox-eff-50 10s linear infinite;
animation-direction:reverse;
}
@keyframes leidabox-eff-50{
to{
transform:rotate(360deg);
}
}
.leida50{
width: 200px;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
background-color: #31FFBA;
border-radius: 50%;
border: 1px solid #33B589;
}
.leida50:before,.leida50:after{
content: '';
width: 120px;
height: 120px;
border-radius: 50%;
border: 1px dashed rgba(0,0,0,0.14);
box-shadow: 0 0 20px rgba(0,0,0,0.1);
position: absolute;
z-index: 3;
}
.leida50:after{
width: 60px;
height: 60px;
position: absolute;
z-index: 10;
}
.line50{
width: 100px;
height: 100px;
background-color: rgba(127,255,212,0.4);
border-radius: 0 0 0 100%;
position: absolute;
left: 0;
top: 100px;
z-index: 100;
animation: zhuaneff50 5s linear infinite;
transform-origin: 100px 0;
}
.line50:after{
content: '';
width: 8px;
height: 8px;
background-color: rgba(255,255,255,0.6);
position: absolute;
top: -4px;
right: -4px;
border-radius: 50%;
}
@keyframes zhuaneff50{
to {
transform: rotate(360deg);
}
}
.guangdian50{
position: absolute;
bottom: 66px;
}
.dian50,.dian50:after,.dian50:before{
width: 7px;
height: 7px;
background-color: #33B589;
position: absolute;
left: -20px;
border-radius: 50%;
animation: eff50 5s steps(6) infinite;
z-index: 999;
}
.dian50:after{
content: '';
width: 6px;
height: 6px;
top: 12px;
left: 44px;
}
.dian50:before{
content: '';
width: 3px;
height: 3px;
top: 40px;
left: 34px;
}
@keyframes eff50{
0% {
opacity: 0;
transform: translate(0, 0);
}
25%{
opacity: 1;
transform: translate(-10px, -18px);
}
50%{
opacity: 0;
transform: translate(-18px, -20px);
}
75%{
opacity: 1;
transform: translate(-24px, -18px);
}
100%{
opacity: 0;
transform: translate(-34px, -24px);
}
}
.guangdian50:after,.guangdian50:before{
content: '';
width: 6px;
height: 6px;
background-color: #33B589;
position: absolute;
top: -100px;
left: 30px;
border-radius: 50%;
z-index: 900;
animation: eff501 5s steps(6) both infinite;
}
.guangdian50:before{
width: 7px;
height: 7px;
top: -20px;
left: 40px;
}
@keyframes eff501{
0% {
opacity: 0;
}
25%{
opacity: 1;
}
50%{
opacity: 0;
}
75%{
opacity: 1;
}
100%{
opacity: 0;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
页面渲染效果
以上就是所有代码,以及简单的思路,希望对你有一些帮助或者启发。
我是 Just,这里是「设计师工作日常」,求点赞求关注!