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

用js+css实现圆环型的进度条——js+css基础积累

如果用js+css实现圆环型的进度条:
在这里插入图片描述
直接上代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>环形进度条</title></head><body><div class="percent"><svg style="transform: rotate(-90deg)"><circle cx="50" cy="50" r="50" /><circle id="circle" cx="50" cy="50" r="50" style="stroke: red" /></svg><div class="num"><h2><span id="per">0</span><span>%</span></h2></div></div><div class="percent"><svg style="transform: rotate(-90deg)"><circle cx="50" cy="50" r="50" /><circle id="circle2" cx="50" cy="50" r="50" style="stroke: #f90" /></svg><div class="num"><h2><span id="per2">0</span><span>%</span></h2></div></div><div class="percent"><svg style="transform: rotate(-90deg)"><circle cx="50" cy="50" r="50" /><circle id="circle3" cx="50" cy="50" r="50" style="stroke: #67c23a" /></svg><div class="num"><h2><span id="per3">0</span><span>%</span></h2></div></div></body><style>body {height: 100vh;display: flex;justify-content: center;align-items: center;margin: 0;}.percent {position: relative;width: 110px;height: 110px;}.percent svg {width: 110px;height: 110px;}.percent svg circle {fill: none;stroke-width: 10;stroke: #1258e3;transform: translate(5px, 5px);/* 设置虚线长度 = 圆的周长(2*50*3.1415926) */stroke-dasharray: 310;/* 设置圆的空白间隙 */stroke-dashoffset: 310;}.percent svg circle:nth-child(1) {stroke-dashoffset: 0;stroke: #f3f3f3;}.percent svg circle:nth-child(2) {stroke-dashoffset: calc(310 - 310 * (0 / 100));stroke-linecap: round;}.percent .num {position: absolute;left: 0;top: 0;width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;}#per {font-size: 22px;}</style><script>circleRender(document.querySelector('#circle'),document.querySelector('#per'),50);circleRender(document.querySelector('#circle2'),document.querySelector('#per2'),10);circleRender(document.querySelector('#circle3'),document.querySelector('#per3'),95);function circleRender(circle, per, percent) {let num = 0;const timer = setInterval(() => {num += 1;if (num > percent) {num = percent;clearInterval(timer);blo = false;}// 设置进度circle.style.strokeDashoffset = `calc(310 - 310*(${num}/100))`;per.innerHTML = num;}, 100);}</script>
</html>

http://www.mrgr.cn/news/53131.html

相关文章:

  • 一插U盘就提示格式化?原因、恢复与预防全攻略
  • 史上最全测评来了,这款性价比最高,买到即赚到,快来get!
  • 必学的20个Excel表格操作Python脚本
  • 基于vue框架的的大学生健康管理系统6z376(程序+源码+数据库+调试部署+开发环境)系统界面在最后面。
  • 【python】数据容器:dict(字典、映射)
  • 刷c语言练习题9(牛客网)
  • python接口自动化测试框架2.0,让你像Postman一样编写测试用例,支持多环境切换、多业务依赖、数据库断言等
  • 【Python】NumPy(一):数据类型、创建数组及基本操作
  • 别墅优选,约克VRF中央空调为家居增添舒适与幸福感
  • c++ 中虚函数和纯虚函数
  • 中科星图(GVE)——使用随机森林方法进行土地分类
  • Vue2的依赖注入(跨级通信)基本使用
  • ST表 C++
  • LSL常见应用场景及示例<三>
  • pip3安装报error: externally-managed-environment,删除EXTERNALLY-MANAGED即可
  • 成语积累学习
  • PHP-laravel框架
  • 苍穹外卖学习笔记(二十六)
  • Null-text Inversion for Editing Real Images using Guided Diffusion Models
  • AI 自学 Lesson2 - 回归(Regression)