CSS: 使用 svg 实现圆形进度条

8 篇文章 3 订阅
2 篇文章 0 订阅

使用 Vue 框架进行实现

<template>
  <div class="mhy-audio-player" @click="onClickAudio">
    <div  class="mhy-audio-player__svg">
      <svg xmlns="http://www.w3.org/2000/svg"
           xmlns:xlink="http://www.w3.org/1999/xlink"
           width="24"
           height="24"
           viewBox="0 0 26 26"
           preserveAspectRatio="xMinYMin meet"
      >
        <circle
          cx="13" cy="13" r="12"
          class="mhy-audio-player__circle1"
        />
        <circle
          cx="13" cy="13" r="12"
          class="mhy-audio-player__circle"
          stroke-dasharray="75"
          :stroke-dashoffset="dashoffset"/>
      </svg>
    </div>
    <div class="mhy-audio-player__status">
      <div
        v-if="isPlay"
        class="mhy-audio-player__status--play">
        <span></span>
        <span></span>
      </div>
      <div
        v-else
        class="mhy-audio-player__status--pause">
        <mhy-icon name="select_arrow"/>
      </div>
    </div>
  </div>
</template>


<script>
  export default {
    name: 'mhy-audio-player',
    data() {
      return {
        isPlay: false,
        process: 0
      };
    },
    computed: {
      dashoffset() {
        return 75 * (1 - this.process);
      }
    },
    methods: {
      onClickAudio() {
        setInterval(() => {
          this.process += 0.01;
        }, 15);
        this.isPlay = !this.isPlay;
      }
    }
  };
</script>


<style lang="scss">
.mhy-audio-player {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  &__svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
  }
  &__circle {
    stroke: rgba(0, 0, 0, 0.1);
    stroke-width: 1;
    stroke:#D3BC8E;
    fill:none;
  }
  &__circle1 {
    stroke: rgba(0, 0, 0, 0.1);
    stroke-width: 1;
    fill:none;
  }
  &__status {
    position: absolute;
    top: 1px;
    left: 1px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    z-index: 5;
    &--play {
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      span {
        display: inline-block;
        width: 3px;
        height: 8px;
        background-color: #D3BC8E;
        border-radius: 3px;
      }
      span:last-child {
        margin-left: 4px;
      }
    }
    &--pause {
      margin-left: 1px;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      transform: rotate(-90deg);
      i {
        font-size: 14px;
        color: #D3BC8E;
      }
    }
  }
  circle {
    transition: stroke-dasharray .2s;
  }
}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值