css实现圆环展示百分比,根据值动态展示所占比例

代码如下

javascript 复制代码
<view class="">
	<view class="circle-chart">
		<view v-if="!!num" class="pie-item" :style="{
				  background: `conic-gradient(var(--one-color) 0%,#E9E6F1 ${num}%)`,
				}"></view>
		<view v-else class="pie-item-copy" :style="{
				  background:'#E9E6F1',
				}"></view>
		<view v-if="!!degNum" class="pie-item" :style="{
				        background: `conic-gradient(var(--two-color) 0%,transparent ${20}%)`,
				        transform: `scaleX(-1) rotate(${degNum}deg)`,
				      }"></view>
		<view class="biaopan">
			<view class="biaopanCot">
				<view class="">
					93
				</view>
				<view class="">
					6小时42分钟
				</view>
			</view>
		</view>
	</view>
</view>
<script>
	export default {
		data() {
			return {
				num: 85, //圆环数值百分比
				degNum: '', //旋转的角度
			}
		},
		watch: {
			num: {
				handler(newValue) {
					if (!!this.num) {
						this.degNum = 360 * (100 - newValue) / 100
					} else {
						this.degNum = ''
					}
				},
				deep: true,
				immediate: true,
			},
		},
	}
</script>
<style scoped lang="scss">
	.circle-chart {
		position: relative;
		--one-color: #11D64C;
		--two-color: #c5ffd7a1;
		width: 460rpx;
		height: 460rpx;
		margin: 0 auto;

		
	}
	.circle-chart .pie-item-copy {
		position: absolute;
		width: 100%;
		height: 100%;
		border-radius: 50%;
		mask: radial-gradient(transparent,
				transparent 174rpx,
				#000 176rpx,
				#000 176rpx,
				#000 100%);
	}
	
	.circle-chart .pie-item {
		position: absolute;
		width: 100%;
		height: 100%;
		border-radius: 50%;
		mask: radial-gradient(transparent,
				transparent 174rpx,
				#000 176rpx,
				#000 176rpx,
				#000 100%);
	
		
	}
	.pie-item:nth-child(1)::before {
		background: linear-gradient(90deg,
				var(--one-color) 50%,
				transparent 51%,
				transparent 100%);
	}
		
	.pie-item:nth-child(2)::before {
		background: linear-gradient(90deg,
				var(--two-color) 50%,
				transparent 51%,
				transparent 100%);
	}
		
	.pie-item::before {
		content: '';
		position: absolute;
		inset: 0;
		width: 56rpx;
		height: 56rpx;
		top: 0;
		left: 202rpx;
		border-radius: 50%;
	}

	.biaopan {
		position: absolute;
		left: 68rpx;
		right: 68rpx;
		top: 68rpx;
		bottom: 68rpx;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.biaopanCot{
		text-align: center;
	}

	< /style>
相关推荐
棉花糖超人36 分钟前
【从0-1的HTML】第2篇:HTML标签
前端·html
exploration-earth44 分钟前
本地优先的状态管理与工具选型策略
开发语言·前端·javascript
OpenTiny社区1 小时前
开源之夏报名倒计时3天!还有9个前端任务有余位,快来申请吧~
前端·github
ak啊1 小时前
WebGL魔法:从立方体到逼真阴影的奇妙之旅
前端·webgl
hang_bro1 小时前
使用js方法实现阻止按钮的默认点击事件&触发默认事件
前端·react.js·html
用户90738703648641 小时前
pnpm是如何解决幻影依赖的?
前端
树上有只程序猿2 小时前
Claude 4提升码农生产力的5种高级方式
前端
傻球2 小时前
没想到干前端2年了还能用上高中物理运动学知识
前端·react.js·开源
咚咚咚ddd2 小时前
前端组件:pc端通用新手引导组件最佳实践(React)
前端·react.js
Lazy_zheng2 小时前
🚀 前端开发福音:用 json-server 快速搭建本地 Mock 数据服务
前端·javascript·vue.js