当前位置: 首页 > news >正文

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

在这里插入图片描述

代码如下

<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>

相关文章:

  • 代码随想录|动态规划|50编辑距离
  • oracle从表B更新拼接字段到表A
  • Fiddler Everywhere 安卓手机抓包
  • 一文了解 GPU 服务器及其在数据中心中的角色
  • 常见的MySQL索引类型
  • Day44打卡 @浙大疏锦行
  • MVCC理解
  • c++ STL 仿函数和适配器(算法常用)
  • Java运行环境配置日志(Log)运行条件,包含鸿蒙HarmonyOS
  • 【Java】CopyOnWriteArrayList
  • 【OSG学习笔记】Day 15: 路径动画与相机漫游
  • 结构性设计模式之Facade(外观)设计模式
  • 【二分图 图论】P9384 [THUPC 2023 决赛] 着色|普及+
  • SpringAI(GA):Nacos2下的分布式MCP
  • vue 打包报错 Cannot find module ‘@vue/cli-plugin-babel/preset‘ - thread-loader
  • vue-16(Vuex 中的模块)
  • 2025年渗透测试面试题总结-腾讯[实习]安全研究员(题目+回答)
  • IEEE ICBCTIS 2025 会议征稿:探索区块链与信息安全的前沿学术之旅​
  • 学习STC51单片机27(芯片为STC89C52RCRC)
  • PageHelper-分页插件
  • 商洛免费做网站公司/广告传媒公司
  • 北京网站建设还公司/阿里巴巴推广
  • 下载的网站模板怎么使用/郑州百度分公司
  • 网站建设做什么/百度app安装免费下载
  • 网站建设所需资料及费用/阿里指数查询官网入口
  • wap手机网站建设方案/it培训班出来现状