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.pswp.cn/bicheng/19646.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/19646.shtml
英文地址,請注明出處:http://en.pswp.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;使其具有更廣泛的應用前景。小型五軸加…