• css,环形


    思路:
    1.先利用conic-gradient属性画一个圆,然后再叠加
    效果图

    在这里插入图片描述

    <template>
      <div class="ring">
        <div class="content">
          <slot></slot>
        </div>
      </div>
    </template>
    <script>
    import { defineComponent, reactive, toRefs, computed, onMounted } from "vue";
    export default defineComponent({
      props: {
        width: {
          type: Number,
          default: 200,
        },
        height: {
          type: Number,
          default: 200,
        },
        color: {
          type: String,
          default: "#fcb844",
        },
        angle: {
          type: Number,
          default: 360,
        },
        total: {
          type: Number,
          default: 360,
        },
        unit: {
          type: String,
          default: "px",
        },
        interval: {
          type: Number,
          default: 20,
        },
        autoPlay: {
          type: Boolean,
          default: true,
        },
      },
      setup(props, { emit }) {
        const datas = reactive({
          timer: null,
          sportAge: 0,
        });
        // 设置渐变
        const bgImage = computed(() => {
          datas.sportAge = props.autoPlay ? datas.sportAge : currentAngle.value;
          return `conic-gradient(${props.color} 0deg, ${props.color} ${datas.sportAge}deg, transparent 0deg)`;
        });
        // 当前度数(deg)
        const currentAngle = computed(() => {
          return ((360 / props.total) * props.angle).toFixed(2);
        });
        // 单位前缀
        const unitSuffix = computed(() => {
          return (data, interval = 0) => {
            return data - interval + props.unit;
          };
        });
        //动画
        const animationPlay = () => {
          datas.timer = setInterval(() => {
            if (currentAngle.value <= datas.sportAge) {
              clearInterval(datas.timer);
              datas.timer = null;
              return;
            }
    
            datas.sportAge++;
          }, 10);
        };
        onMounted(() => {
          props.autoPlay ? animationPlay() : "";
        });
        return {
          ...toRefs(datas),
          bgImage,
          unitSuffix,
        };
      },
    });
    </script>
    <style lang="less" scoped>
    .ring {
      position: relative;
      width: v-bind(unitSuffix(width));
      height: v-bind(unitSuffix(height));
      display: flex;
      align-items: center;
      justify-content: center;
      &::before {
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        width: v-bind(unitSuffix(width));
        height: v-bind(unitSuffix(height));
        // background-color: red; /* 对于不支持渐变的浏览器 */
        background-image: v-bind(bgImage);
        border-radius: 50%;
        transform: scale(-1, 1);
      }
      &::after {
        content: "";
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: v-bind(unitSuffix(width, interval));
        height: v-bind(unitSuffix(height, interval));
        border-radius: 50%;
        background-color: #ffffff;
      }
      .content {
        position: absolute;
        z-index: 3;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
    </style>
    
    
    
    
    
    
    • 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
    <template>
      <div class="ring_box">
        <div class="inner">
          <ring
            :width="180"
            :height="180"
            :color="innerColor"
            :interval="interval"
          >
          </ring>
          <div class="out">
            <ring :total="3454" :angle="2234" :interval="interval">
              <ring
                :width="175"
                :height="175"
                :color="innerColor"
                :interval="interval / 2"
              >
                <div>内容</div>
              </ring>
            </ring>
          </div>
        </div>
      </div>
    </template>
    <script lang="ts">
    import ring from "./ring.vue";
    import { defineComponent, reactive, toRefs } from "vue";
    export default defineComponent({
      components: {
        ring,
      },
      setup(props) {
        const datas = reactive({
          width: 180,
          height: 180,
          outColor: "",
          innerColor: "#feedd1",
          interval: 40,
        });
        return {
          ...toRefs(datas),
        };
      },
    });
    </script>
    <style lang="less" scoped>
    .ring_box {
      width: 300px;
      height: 300px;
      display: flex;
      align-items: center;
      justify-items: center;
      position: relative;
      .out,
      .inner {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
      }
    }
    </style>
    
    
    
    • 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
  • 相关阅读:
    Jmeter性能 —— 事务控制器
    算法竞赛进阶指南 搜索 0x28 IDA*
    华为OD机试真题- 非严格递增连续数字序列-2023年OD统一考试(B卷)
    Typora设置代码块Mac风格三个圆点
    day13【代码随想录】环形链表II、环形链表、快乐数、各位相加、丑数、丑数||
    AGI之MFM:《多模态基础模型:从专家到通用助手》翻译与解读之与LLM协同工作的多模态智能体、结论和研究趋势
    JAVA毕业设计客服管理系统计算机源码+lw文档+系统+调试部署+数据库
    MATLAB中创建并计算多项式
    【论文翻译】2.5PC:一个更快的非阻塞原子提交协议
    Javascript的同步与异步,异步的宏任务与微任务——事件循环
  • 原文地址:https://blog.csdn.net/qq_41893686/article/details/133102546