vue2 css 简单圆形进度条

超级简单的一个小圆形进度条,主要是利用两个半圆+ border + 旋转,样式十分简单。

打个底,有什么需要改的再次基础上再做修改~

效果图

组件部分

模板:

<template>
    <view class="circle-box" key="key"
    :style="{'--activecolor': activeColor,'--inactivecolor': inActiveColor,'--leftRotate':leftRotate+'deg','--rightRotate':rightRotate+'deg'}">
            <view class="circle left">
                 <view class="circle-sub" :style="'border-width: '+ borderWidth +';-webkit-transform: rotate('+ leftRotate +'deg);'"></view>  
            </view>
            <view class="circle right">
                 <view class="circle-sub" :style="'border-width: '+ borderWidth +';-webkit-transform: rotate('+ rightRotate +'deg);'"></view>  
            </view>
            <view class="circle-text">
                <view v-if="showRate" class="circle-num">{{ rate.toFixed(2) }} %</view>
                <view v-if="content" class="circle-num">{{ content }}</view>
                <view v-if="tip">{{ tip }}</view>
                <slot></slot>
            </view>
        </view>
    </view>
</template>

js部分

    export default {
        name:"circleProgress",
        props: {
            rate: {
                type: Number,
                default: 0
            },
            showRate: {
                type: Boolean,
                default: false
            },
            activeColor: {
                type: String,
                default: '#3c9cff'
            },
            inActiveColor: {
                type: String,
                default: '#eeeeee'
            },
            borderWidth: {
                type: String,
                default: '10px'
            },
            content: {
                type: String,
                default: ''
            },
            tip: {
                type: String,
                default: ''
            }
        },
        data() {
            return {
                refresh: true
            };
        },
        computed: {
            key(){
                return this.rate + Math.random() * 100
            },
            rightRotate() {
                if(this.rate <= 50) {
                    return 45 + this.rate * 3.6
                } else {
                    return 225
                }
            },
            leftRotate() {
                if(this.rate > 50) {
                    return 45 + (this.rate - 50) * 3.6
                } else {
                    return 45
                }
            },
        },
    }

css部分

.circle-box{
    width: 100%;
    height: 100%;
    border-radius: 50%;
    box-sizing: border-box;
    position: relative;
}

.circle{
    width: 50%;
    height: 100%;
    box-sizing: border-box;
    position: absolute;
    overflow:hidden;
    top: 0;
}

.left{
    left: 0;
}

.right{
    right: 1px;
}

.circle > .circle-sub{
    width: 200%;   
    height: 100%;   
    border:10px solid transparent;   
    border-radius: 50%;   
    box-sizing: border-box;
    position: absolute;   
    top:0;  
    z-index: 3;
}

.right .circle-sub{   
    border-top:10px solid var(--inactivecolor);   
    border-right:10px solid var(--inactivecolor);  
    border-left:10px solid var(--activecolor);   
    border-bottom:10px solid var(--activecolor);    
    right:0;
}

.left .circle-sub{   
    border-top:10px solid var(--activecolor);   
    border-right:10px solid var(--activecolor); 
    border-bottom:10px solid var(--inactivecolor);   
    border-left:10px solid var(--inactivecolor);      
    left:0;
}

.circle-text {
    font-weight: bold;
    font-size: 14rpx;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    align-content: center;
    color: var(--activecolor);
    padding-top: 15%;
}

.circle-num {
    font-size: 18rpx;
    padding: 3px 0;
    flex-basis: 100%;
}

引用

// 引入
import circleProgress from '@/components/circle-progress/circle-progress.vue'
...
// 组件
components: { circleProgress },
// 模板使用
<circle-progress :rate="rate">
    <template v-slot>
        <view class="circle-num">{{ doneNum }}</view>
        <view>已完成</view>
    </template>
</circle-progress>
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值