温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用CSS实现圆形进度条

发布时间:2022-03-01 09:33:37 来源:亿速云 阅读:121 作者:小新 栏目:web开发

这篇文章主要介绍了如何使用CSS实现圆形进度条,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

  首先一个父级div设置相对定位,内部含有四个半圆div和一个用于遮罩的小圆div

  实现步骤

  先写出基本html结构

  <div class="box">

  <div class="bg1"></div>

  <div class="bg2"></div>

  <div class="pr1"></div>

  <div class="pr2"></div>

  <div class="content"></div>

  </div>

  父级div和content添加样式

  .box{

  position: relative;

  }

  .content {

  top: 10px;

  left: 10px;

  width: 100px;

  height: 100px;

  border-radius: 50%;

  position: absolute;

  background:red;

  z-index: 5;

  }

  当前效果:

  添加第一个背景半圆

  .bg1{

  position: absolute;

  width: 60px;

  height: 120px;

  border-radius: 120px 0 0 120px;

  z-index: 3;

  background: sandybrown;

  }

  添加第二个背景半圆

  .bg2{

  left: 60px;

  position: absolute;

  width: 60px;

  height: 120px;

  border-radius: 0px 120px 120px 0;

  z-index: 1;

  background: sandybrown;

  }

  添加第一个进度半圆,这个时候,去页面调整rotate的角度可以看到进度旋转

  .pr1 {

  position: absolute;

  left: 60px;

  width: 60px;

  height: 120px;

  border-radius: 0px 120px 120px 0px;

  z-index: 2;

  background: forestgreen;

  transform: rotate(-180deg);

  transform-origin: 0px 60px;

  }

  添加第二个半圆,第一个半圆只能旋转到50%,所以需要第二个半圆来走完剩下的一半

  .pr2 {

  position: absolute;

  left: 60px;

  border-radius: 0px 120px 120px 0px;

  z-index: 4;

  background: forestgreen;

  transform: rotate(-180deg);

  transform-origin: 0px 60px;

  }

  添加动画函数,在分别把动画函数添加到.pr1和.pr2中,在实际需求中可以用js控制连个进度半圆的旋转角度

  .pr1 {

  ...

  animation: pr1A 5s infinite linear forwards;

  }

  .pr2 {

  ...

  animation: pr2A 5s infinite linear forwards;

  }

  @keyframes pr1A {

  0% {

  transform: rotate(-180deg);

  }

  50% {

  transform: rotate(0deg);

  }

  100% {

  transform: rotate(0deg);

  }

  }

  @keyframes pr2A {

  0% {

  transform: rotate(-180deg);

  }

  100%{

  width: 60px;

  height: 120px;

  transform: rotate(180deg);

  }

  }

感谢你能够认真阅读完这篇文章,希望小编分享的“如何使用CSS实现圆形进度条”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css
AI