使用css實現(xiàn)雷達效果
效果圖
雷達.png
注意事項
- 扇形實現(xiàn):將正方形移動到1/4圓處透葛,利用overflow: hidden;將其切割成扇形
代碼
<!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 style="display: flex; justify-content: center; padding: 100px">
<div class="radar">
<div class="fan"></div>
</div>
</div>
<style>
/* 繪制雷達外圈 */
.radar {
/* 隱藏多余部分 */
overflow: hidden;
position: relative;
width: 300px;
height: 300px;
border-radius: 50%;
background: #fff;
border: 1px solid #1890ff;
/* 避免出現(xiàn)邊框問題 */
box-sizing: border-box;
}
/* 繪制雷達中間十字線的豎線 */
.radar::before {
width: 150px;
height: 300px;
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
box-sizing: border-box;
border-right: 1px solid #1890ff;
}
/* 繪制雷達中間十字線的橫線 */
.radar::after {
width: 300px;
height: 150px;
content: '';
display: block;
box-sizing: border-box;
border-bottom: 1px solid #1890ff;
}
/* 繪制雷達內(nèi)圈 */
.fan {
position: absolute;
top: 50%;
left: 50%;
/* 居中 */
transform: translate(-50%, -50%);
border-radius: 50%;
box-sizing: border-box;
border: 1px solid #1890ff;
width: 150px;
height: 150px;
}
/* 繪制雷達掃描的扇形 */
.fan::after {
content: '';
width: 150px;
height: 150px;
display: block;
box-sizing: border-box;
position: relative;
top: -50%;
right: -50%;
/* 移動旋轉(zhuǎn)原點 */
transform-origin: 0% 100%;
border-bottom: 3px solid transparent;
border-image: linear-gradient(to right, transparent, #1890ff);
/* border-image-slice: 3; */
background: transparent;
background-image: linear-gradient(to right, transparent, #5ba9f3);
animation: rotateAnimate 2s linear infinite;
}
/* 動畫 */
@keyframes rotateAnimate {
from {
transform: rotate(0deg);
/* transform: rotate(0deg) skew(-10deg); */
}
to {
transform: rotate(360deg);
/* transform: rotate(360deg) skew(-10deg); */
}
}
</style>
</body>
</html>