Vue实现环形进度条方法组件

<template>
<div class="wrap">
<div class="circle" v-bind:class="{ 'clip-auto': isActive.circle }">
<div class="percent left" ref='left' v-bind:style="{
'-webkit-transform':'rotate('+(18/5)*InitialVal+'deg)',
'-ms-transform':'rotate('+(18/5)*InitialVal+'deg)',
'-moz-transform':'rotate('+(18/5)*InitialVal+'deg)',
'transform':'rotate('+(18/5)*InitialVal+'deg)'
}"></div>
<div class="percent right" v-bind:class="{'wth0': isActive.right }"></div>
</div>
<div class="num">{{InitialVal }}</div>
<div class="ring-title">
<h3>{{datas.title}}</h3>
<p class="ellipsis">{{datas.description}}</p>
</div>
</div>
</template>
<script>
export default {
data () {
return {
msg : 'ring',
InitialVal : 0,
isActive : {
circle : false,
right : true
}
}
},

props:{
'datas':Object,
// 'sum':Number,
// 'titles':String,
// 'description':String,
},
methods:{
},
mounted(){//挂载结束调用的函数
var percent = 0
var sum = this.datas.sum;
var _this = this;
var loading=setInterval(function(){
if(percent == sum){
clearTimeout(loading);
}
if(percent>50){
_this.isActive.right = false;
_this.isActive.circle = true;
}
_this.InitialVal = percent;
percent++;
},10);
}

}
</script>

<style lang='scss' scoped>

    *{
        margin: 0;
        padding: 0;
    }
    .wrap,.circle,.percent{
        position: absolute;
        width: 100px;
        height: 100px;
        border-radius: 50%;
    }
    .wrap{
        position: relative;
        top:50px;
        left:50px;
        display: inline-block;
        background-color: #ccc;
    }
    .circle{
        box-sizing: border-box;
        border:20px solid #ccc;
        clip:rect(0,100px,100px,50px);
    }
    .clip-auto{
        clip:rect(auto, auto, auto, auto);
    }
    .percent{
        box-sizing: border-box;
        top:-20px;
        left:-20px;
    }
    .left{
        transition:transform ease;
        border:20px solid #00ff00;
        clip: rect(0,50px,100px,0);
    }
    .right{
        border:20px solid #00ff00;
        clip: rect(0,100px,100px,50px);
    }
    .wth0{
        width:0;
    }
    .num{
        position: absolute;
        box-sizing: border-box;
        width: 60px;
        height: 60px;
        line-height: 60px;
        text-align: center;
        font-size: 40px;
        left: 20px;
        top: 20px;
        border-radius: 50%;
        background-color: #fff;
        z-index: 1;
    }
    .ring-title{
        width: 100%;
        position: absolute;
        bottom: -50px;
        text-align: center;
    }

</style>

转载于:https://my.oschina.net/lslDn/blog/1935974

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用CSS3的旋转和动画效果来实现环形进度条,具体步骤如下: 1. 创建一个包含进度条的容器,设置宽度和高度,并设置背景颜色。 2. 创建一个表示进度的元素,设置宽度和高度,并设置背景颜色。 3. 将进度条容器设置为相对定位,将进度元素设置为绝对定位,并将其旋转180度。 4. 使用CSS3动画将进度元素旋转回来,同时设置动画时间。 5. 使用CSS3动画将进度元素的宽度从0逐渐变为100%,同时设置动画时间。 6. 通过调整进度元素的旋转角度和宽度来改变进度条的进度。 下面是一个实现环形进度条的示例代码: HTML代码: ```html <div class="progress-container"> <div class="progress-bar"></div> </div> ``` CSS代码: ```css .progress-container { position: relative; width: 100px; height: 50px; background-color: #eee; border-radius: 50px; } .progress-bar { position: absolute; top: 0; left: 0; width: 50px; height: 100px; background-color: #f00; border-radius: 50px; transform: rotate(180deg); animation: rotate 2s linear forwards; } @keyframes rotate { from { transform: rotate(180deg); } to { transform: rotate(0deg); } } .progress-bar::before { content: ""; position: absolute; top: 0; left: 0; width: 50px; height: 100%; background-color: #f00; border-radius: 50px 0 0 50px; animation: progress 2s linear forwards; } @keyframes progress { from { width: 0; } to { width: 100%; } } ``` 在上面的代码中,我们创建了一个宽度为100px,高度为50px的半环形进度条容器。进度条容器中包含一个宽度为50px,高度为100px的进度元素。我们使用CSS3的transform属性将进度元素旋转180度,并使用animation属性将其旋转回来。同时,我们使用animation属性将进度元素从0逐渐变为100%的宽度,以显示进度条的进度。 你可以通过调整进度元素的旋转角度和宽度来改变进度条的进度。例如,如果你想要进度条的进度达到50%,可以将进度元素的旋转角度设置为135度,将宽度设置为50%。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值