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>
相关推荐
weixin_4080996710 分钟前
【完整教程】天诺脚本如何调用 OCR 文字识别 API?自动识别屏幕文字实战(附代码)
前端·人工智能·后端·ocr·api·天诺脚本·自动识别文字脚本
吴声子夜歌11 分钟前
ES6——Generator函数详解
前端·javascript·es6
吴声子夜歌13 分钟前
ES6——Set和Map详解
前端·javascript·es6
码喽7号43 分钟前
vue学习四:Axios网络请求
前端·vue.js·学习
粥里有勺糖1 小时前
视野修炼-技术周刊第129期 | 上一次古法编程是什么时候
前端·javascript·github
whuhewei2 小时前
JS获取CSS动画的旋转角度
前端·javascript·css
蓝黑20202 小时前
Vue组件通信之v-model
前端·javascript·vue
像素之间2 小时前
为什么运行时要加set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve
前端·javascript·vue.js
M ? A2 小时前
Vue转React实战:defineProps精准迁移实战
前端·javascript·vue.js·经验分享·react.js·开源·vureact
西陵2 小时前
别再写 Prompt 了Spec Mode 才是下一代 AI 编程范式
前端·人工智能·ai编程