CSS3圓形進度條效果

antzone發表於2018-06-20

分享一段程式碼例項,它利用css3實現了圓形進度條效果。

準確的說應該是環形進度條,程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
* {
  margin: 0;
  padding: 0;
}
.progress-ring {
  width: 160px;
  height: 160px;
  border: 20px solid green;
  border-radius: 50%;
  box-sizing: border-box;
  position: absolute;
  top: 0;
  left: 0;
}
.progress-track {
  width: 160px;
  height: 160px;
  border: 20px solid green;
  border-radius: 50%;
  box-sizing: border-box;
  position: absolute;
  clip: rect(0px,80px,160px,0px);
  top: -20px;
  left: -20px;
}
.progress-left {
  position: relative;
  width: 160px;
  height: 160px;
  border: 20px solid goldenrod;
  border-radius: 50%;
  box-sizing: border-box;
  position: absolute;
  clip: rect(0px,80px,160px,0px);
  top: -20px;
  left: -20px;
  transform: rotate(3.6deg);
  transition: transform 2s linear;
  animation: mymove 3s linear forwards;
}
.progress-right {
  width: 160px;
  height: 160px;
  border: 20px solid goldenrod;
  border-radius: 50%;
  box-sizing: border-box;
  position: absolute;
  clip: rect(0px,80px,160px,0px);
  top: -20px;
  left: -20px;
  transform: rotate(180deg);
  opacity: 0;
  animation: toggle 0s ease 1.5s forwards;
}
.progress-cover {
  position: relative;
  width: 160px;
  height: 160px;
  border: 20px solid green;
  border-radius: 50%;
  box-sizing: border-box;
  position: absolute;
  clip: rect(0px,80px,160px,0px);
  top: -20px;
  left: -20px;
  opacity: 1;
  animation: toggleq 0s ease 1.5s forwards;
}
@keyframes mymove {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
@keyframes toggle {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@keyframes toggleq {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
</style>
</head>
<body>
  <div class="progress-ring">
    <div class="progress-track"></div>
    <div class="progress-left"></div>
    <div class="progress-right"></div>
    <div class="progress-cover"></div>
    <div class="inn"></div>
  </div>
</body>
</html>

相關文章