svg实现一个圆形以及方形的环形进度条

1. svg实现圆形进度条

效果图:

1. 写个假接口:

let res = {curLegendList: [{ progress: "87", name: "进度1",color:"#00fe41" },{ progress: "66", name: "进度2" ,color:"orange"},{ progress: "50", name: "进度3",color:"#00fe41" },{ progress: "25", name: "进度4" ,color:"red"},{ progress: "87", name: "进度1",color:"#00fe41" },{ progress: "66", name: "进度2" ,color:"orange"},{ progress: "50", name: "进度3",color:"#00fe41" },{ progress: "25", name: "进度4" ,color:"red"},]}

2. 编写css

  * {margin: 0;padding: 0;box-sizing: border-box;font-family: '微软雅黑', sans-serif;}.container {width: 30px;height: 30px;}.zcy_box {position: relative;width: 250px;height: 150px;display: flex;align-items: center;background-color: darkgoldenrod;}.zcy_box .zcy_percent {position: relative;width: 150px;height: 150px;}.zcy_box .zcy_percent svg {position: relative;width: 150px;height: 150px;}.zcy_box .zcy_percent svg circle {width: 35px;height: 35px;fill: none;stroke-width: 10;stroke: #000;transform: translate(5px, 5px);stroke-dasharray: 440;stroke-dashoffset: 440;stroke-linecap: round;}.zcy_box .zcy_percent .zcy_number {position: absolute;top: 0;left: 0;width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;color: #767576;}.zcy_box .zcy_percent .zcy_number h2 {font-size: 24px;}.zcy_box .zcy_percent .zcy_number span {font-size: 24px;}.zcy_box .text {font-size: 24px;padding: 10px 0 0;color: #999;font-weight: 400;letter-spacing: 1px;}

3. 写个公用的js方便调用,可以自己改造

function htmlFunc(name, progress, color) {var html = '';html += '<div class="zcy_box">';html += '<h2 class="text">'+name+'</h2>';html += '<div class="zcy_percent">';html += '<div class="zcy_number">';html += '<h2>'+progress+'<span>%</span></h2>';html += '</div>';html += '<svg>';html += '<circle style="stroke-dashoffset: 0;stroke: #ccc;" cx="70" cy="70" r="40"></circle>';html += '<circle style="stroke-dashoffset: calc(440 - (440 * '+progress+')/180);stroke: '+color+';" cx="70" cy="70" r="40"></circle>';html += '</svg>';html += '</div>';html += '</div>';return html;}

4. 调用js以及传数据进去

let curLegendList = res.curLegendList;var curHtml='';for(let i=0;i<curLegendList.length;i++){curHtml += htmlFunc(curLegendList[i].name,curLegendList[i].progress,curLegendList[i].color);}$(".app").html(curHtml);
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>SVG实现圆形进度条</title><style>* {margin: 0;padding: 0;box-sizing: border-box;font-family: '微软雅黑', sans-serif;}.container {width: 30px;height: 30px;}.zcy_box {position: relative;width: 250px;height: 150px;display: flex;align-items: center;background-color: darkgoldenrod;}.zcy_box .zcy_percent {position: relative;width: 150px;height: 150px;}.zcy_box .zcy_percent svg {position: relative;width: 150px;height: 150px;}.zcy_box .zcy_percent svg circle {width: 35px;height: 35px;fill: none;stroke-width: 10;stroke: #000;transform: translate(5px, 5px);stroke-dasharray: 440;stroke-dashoffset: 440;stroke-linecap: round;}.zcy_box .zcy_percent .zcy_number {position: absolute;top: 0;left: 0;width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;color: #767576;}.zcy_box .zcy_percent .zcy_number h2 {font-size: 24px;}.zcy_box .zcy_percent .zcy_number span {font-size: 24px;}.zcy_box .text {font-size: 24px;padding: 10px 0 0;color: #999;font-weight: 400;letter-spacing: 1px;}</style><script src="./jquery.min.js"></script>
</head><body><div class="app"></div></body>
<script>var obj = {curLegendList: [{ progress: "87", name: "进度1",color:"#00fe41" },{ progress: "66", name: "进度2" ,color:"orange"},{ progress: "50", name: "进度3",color:"#00fe41" },{ progress: "25", name: "进度4" ,color:"red"},{ progress: "87", name: "进度1",color:"#00fe41" },{ progress: "66", name: "进度2" ,color:"orange"},{ progress: "50", name: "进度3",color:"#00fe41" },{ progress: "25", name: "进度4" ,color:"red"},]}function htmlFunc(name, progress, color) {var html = '';html += '<div class="zcy_box">';html += '<h2 class="text">'+name+'</h2>';html += '<div class="zcy_percent">';html += '<div class="zcy_number">';html += '<h2>'+progress+'<span>%</span></h2>';html += '</div>';html += '<svg>';html += '<circle style="stroke-dashoffset: 0;stroke: #ccc;" cx="70" cy="70" r="40"></circle>';html += '<circle style="stroke-dashoffset: calc(440 - (440 * '+progress+')/180);stroke: '+color+';" cx="70" cy="70" r="40"></circle>';html += '</svg>';html += '</div>';html += '</div>';return html;}let curLegendList = res.curLegendList;var curHtml='';for(let i=0;i<curLegendList.length;i++){curHtml += htmlFunc(curLegendList[i].name,curLegendList[i].progress,curLegendList[i].color);}$(".app").html(curHtml);</script></html>

2. svg实现方形进度条

效果图

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="./jq.js"></script></head><body><div id="app"></div></body><script>const circleGirth = 2 * Math.PI * 100 // 圆角的圆的周长const width = 100 - 2 * 10 // 正方形的边长const girth = circleGirth + 4 * width // 圆角矩形总周长const dasharray = `${0.60*0.426*0.5 * girth} ${girth}`const curHtml = `<svg width="120" height="50"><rect fill="none" x="10" y="10" rx="10" width="100" height="30" stroke="#ebedf0" stroke-width="5" /><rect fill="none" x="10" y="10" rx="10" width="100" height="30" stroke="#50D4AB" stroke-width="5"  stroke-dasharray="${dasharray}"/></svg>`;$("#app").html(curHtml);</script></html>

五分钟学会各种环形进度条

方形进度条从上面链接改造而来,大家可以去看看

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/19646.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

gitlab服务器迁移(亲测有效)

描述&#xff1a;最近公司迁移gitlab&#xff0c;我没有迁移过&#xff0c;经过网上查找资料最终完成迁移&#xff0c;途中也遇到挺多坑和两个问题&#xff0c;希望能帮到你。 新服务器安装gitlab 注意&#xff1a;新服务器gitlab版本也需要和旧版本一致。 首先查看原Gitlab…

基于Python实现地震数据可视化的设计与实现

基于Python实现地震数据可视化的设计与实现 “Design and Implementation of Earthquake Data Visualization using Python” 完整下载链接:基于Python实现地震数据可视化的设计与实现 文章目录 基于Python实现地震数据可视化的设计与实现摘要第一章 引言1.1 研究背景1.2 研究…

RabbitMQ(三)SpringBoot整合,可靠性投递,死信队列,延迟队列,消费端限流,消息超时

文章目录 整合Springboot概述消费者生产者 消息可靠性投递故障原因解决方案生产者端消息确认机制&#xff08;故障情况1&#xff09;故障情况2解决方案故障情况3解决方案 消费端限流概念 消息超时概念队列层面&#xff1a;配置队列过期消息本身&#xff1a;配置消息过期 死信队…

C++中的虚函数和纯虚函数

目录 摘要 虚函数&#xff08;Virtual Functions&#xff09; 定义 用法 纯虚函数&#xff08;Pure Virtual Functions&#xff09; 定义 用法 需要避开的坑 总结 摘要 在C中&#xff0c;我们经常会在开发中使用到虚函数&#xff08;Virtual Functions&#xff09;和…

如何有效屏蔽手机上的骚扰电话20240530

如何有效屏蔽手机上的骚扰电话 引言 最近&#xff0c;我的手机经常接到954开头的7位数字座机电话&#xff0c;这些骚扰电话让我非常困扰。由于我经常点外卖&#xff0c;无法屏蔽所有陌生号码&#xff0c;因此需要一个既能屏蔽特定前缀的骚扰电话&#xff0c;又不影响日常生活…

英伟达(NVIDIA)H100性能及应用场景

英伟达H100是一款性能强大的GPU芯片&#xff0c;其关键性能参数和应用领域可以归纳如下&#xff1a; 一、性能参数 架构&#xff1a;H100采用了新一代的Hopper架构&#xff0c;拥有高达1.8万亿次/秒的张量处理能力和高达840 TFLOPS的FP8张量性能。CUDA核心数&#xff1a;H100…

STM32学习和实践笔记(33):待机唤醒实验

1.STM32待机模式介绍 很多单片机具有低功耗模式&#xff0c;比如MSP430、STM8L等&#xff0c;我们的STM32也不例外。默认情况下&#xff0c;系统复位或上电复位后&#xff0c;微控制器进入运行模式。在运行模式下&#xff0c;HCLK 为CPU提供时钟&#xff0c;并执行程序代码。这…

kafka学习笔记06

Kafka数据存储流程和log日志讲解 讲解分布式应用核心CAP知识 Kafka数据可靠性保证原理之副本机制Replica介绍《上》 Kafka数据可靠性保证原理之副本机制Replica介绍《下》 Kafka数据可靠性保证原理之ISR机制讲解 Kafka的HighWatermark的作用你知道多少

暑期来临,AI智能视频分析方案筑牢防溺水安全屏障

随着夏季暑期的来临&#xff0c;未成年人溺水事故频发。传统的防溺水方式往往依赖于人工巡逻和警示标识的设置&#xff0c;但这种方式存在人力不足、反应速度慢等局限性。近年来&#xff0c;随着视频监控智能分析技术的不断发展&#xff0c;其在夏季防溺水中的应用也日益凸显出…

ubuntu22 搭建nginx高可用集群(VIP(keepalived) + 负载均衡)

#在所有节点安装nginx #ps: 如果要使用tcp流转发&#xff1a;需用二进制包安装 make编译时加入stream流的参数。 推荐直接安装openresty【默认支持stream等nginx模块&#xff0c;还附带了很多常用的lua库】 apt install -y net-tools sudo apt install -y nginx vim /etc/…

恒创科技:无法与服务器建立安全连接怎么解决?

在使用互联网服务时&#xff0c;有时会出现无法与服务器建立安全连接的问题&#xff0c;此错误消息通常出现在尝试访问需要安全连接的网站(例如使用 HTTPS 的网站)时&#xff0c;这可能是由于多种原因造成的&#xff0c;以下是一些常见的解决方法&#xff0c;帮助你解决问题。 …

聚道云软件连接器:打通易快报与保融资金系统,实现高效财务管理

一、客户介绍&#xff1a;食品企业&#xff0c;引领健康零食新风尚 某食品行业的公司作为国内领先的集研发、生产、销售为一体的现代化辣味休闲食品企业。该公司秉承“健康、美味、安全”的理念&#xff0c;不断创新和进取&#xff0c;为消费者带来了一系列美味可口的辣味休闲…

msvcp100.dll丢失怎样修复?几种快速有效修复msvcp100.dll丢失的方法

在使用电脑时是不是遇到过关于msvcp100.dll丢失文件丢失的情况&#xff1f;出现这样的情况有什么办法可以将丢失的msvcp100.dll文件快速恢复&#xff1f;今天的这篇文章就将教大家几种能够有效的解决msvcp100.dll丢失问题的方法。 方法一&#xff1a;重启电脑 重启电脑是一种简…

参数高效微调PEFT(三)快速入门LoRA、AdaLoRA

参数高效微调PEFT(三)快速入门LoRA、AdaLoRA 我们已经了解了HuggingFace中peft库的几种高效微调方法。 参数高效微调PEFT(一)快速入门BitFit、Prompt Tuning、Prefix Tuning 参数高效微调PEFT(二)快速入门P-Tuning、P-Tuning V2 今天我们继续了解大火的高效微调方法LoRA以及…

MyBatis基础理解教程,详细分步基础查询表数据练习(通俗易懂、实时更新)

一、MyBatis是什么 MyBatis 是一个持久层框架&#xff0c;简化JDBC开发&#xff0c;它提供了一个从 Java 应用程序到 SQL 数据库的桥梁&#xff0c;用于数据的存储、检索和映射。MyBatis 支持基本的 SQL 操作、高级映射特性以及与 Maven 等构建工具的集成。 二、持久层是什么…

IDEA增加.gitignore文件后的处理

IDEA增加 .gitignore 文件后&#xff0c;但还是被 git 跟踪了。 我的文件已经被添加到 .gitignore 中&#xff0c;但仍然被 Git 跟踪&#xff0c; 文件被修改后commint中就会存在此文件。 原因: 文件已经被提交过了 如果文件在添加到 .gitignore 之前已经被提交到 Git 仓库中,…

Spring boot集成通义千问大模型

Spring boot集成通义千问大模型 背景 我在用idea进行java开发时发现了通义灵码这款免费的智能代码补全插件&#xff0c;用了一段时间了&#xff0c;感觉很不错。就想着在自己的项目中也能集成通义千问大模型实现智能回答&#xff0c;毕竟对接openai需要解决网络问题&#xff…

战略合作 | 竹云赋能雁塔区数字经济高质量发展

2024年5月30日&#xff0c;由西安市数据局指导&#xff0c;中共西安市雁塔区委、西安市雁塔区人民政府主办的 “雁塔区企业数字化转型发展大会” 在西安开幕。 本次活动以“数智雁塔&#xff0c;引领未来”为主题&#xff0c;特邀业内150余位政府、数字化服务企业、传统行业企…

Kubernetes 之 DaemonSet 基本原理

Kubernetes 之 DaemonSet 基本原理 DaemonSet 定义 DaemonSet 确保全部&#xff08;或者某些&#xff09;节点上运行一个 Pod 的副本。 当有节点加入集群时&#xff0c; 也会为他们新增一个 Pod 。 当有节点从集群移除时&#xff0c;这些 Pod 也会被回收。删除 DaemonSet 将会…

先导微型数控桌面式加工中心

随着数控技术、传感器技术、人工智能等技术的不断发展&#xff0c;制造业的快速发展和技术的不断进步&#xff0c;小型五轴加工中心的性能将不断提升&#xff0c;五轴联动技术作为解决异性复杂零件高效优质加工问题的重要手段&#xff0c;使其具有更广泛的应用前景。小型五轴加…