css 雷达

使用css实现雷达效果

效果图

雷达.png

注意事项

  • 扇形实现:将正方形移动到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;
        /* 避免出现边框问题 */
        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;
      }

      /* 绘制雷达内圈 */
      .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%;
        /* 移动旋转原点 */
        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>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 目录 标准盒模型和怪异盒模型 link标签和import标签的区别 flex布局 BFC 垂直居中的方法 块元素和...
    Grandperhaps阅读 3,165评论 0 4
  • 在预备做这个动效之前,参考了网上的教程,结果当然是需要借助贝塞尔曲线。本人却偏好css,因为纯css实现贝赛尔曲线...
    andreaxiang阅读 14,709评论 0 10
  • 一、CSS中的属性和取值 1.文本类属性: text-align属性:此标签内容的水平对齐方式,内容须为具体文字/...
    刘远舟阅读 3,529评论 0 1
  • 盒子模型(CSS重点) 其实,CSS就三个大模块: 盒子模型 、 浮动 、 定位,其余的都是细节。要求这三部分,...
    xlystar阅读 5,863评论 0 1
  • 一. 初识CSS CSS文档:https://www.w3school.com.cn/cssref/index.a...
    只是甲阅读 786评论 0 0