demo地址:

https://lyf521.github.io/docs/blog/animation/cssCircle.html

采用定位, 左右各一个半圆, css的 动画属性,和 2D旋转 transform: rotate(45deg)

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>使用CSS3实现圆形进度条</title>
  8. <style>
  9. .circle_process{
  10. position: relative;
  11. width: 199px;
  12. height: 200px;
  13. }
  14. .circle_process .wrapper{
  15. width: 100px;
  16. height: 200px;
  17. position: absolute;
  18. top: 0;
  19. overflow: hidden;
  20. }
  21. .circle_process .right{
  22. right: 0;
  23. }
  24. .circle_process .left{
  25. left: 0;
  26. }
  27. .circle_process .circle{
  28. width: 160px;
  29. height: 160px;
  30. border: 20px solid transparent;
  31. border-radius: 50%;
  32. position: absolute;
  33. top: 0;
  34. transform: rotate(-135deg);
  35. }
  36. .circle_process .rightcircle{
  37. border-top: 20px solid red;
  38. border-right: 20px solid red;
  39. right: 0;
  40. -webkit-animation: circle_right 5s linear infinite;
  41. }
  42. .circle_process .leftcircle{
  43. border-bottom: 20px solid red;
  44. border-left: 20px solid red;
  45. left: 0;
  46. opacity: 0;
  47. -webkit-animation: circle_left 5s linear infinite;
  48. }
  49. .circle_process .show{
  50. width: 200px;
  51. height: 200px;
  52. font-size: 30px;
  53. position: absolute;
  54. left: 0;
  55. top: 0;
  56. text-align: center;
  57. line-height: 200px;
  58. }
  59. .circle_process #rightcircle{
  60. border-top: 20px solid red;
  61. border-right: 20px solid red;
  62. right: 0;
  63. /* -webkit-animation: circle_right 5s linear infinite; */
  64. }
  65. .circle_process #leftcircle{
  66. border-bottom: 20px solid red;
  67. border-left: 20px solid red;
  68. left: 0;
  69. opacity: 0;
  70. /* -webkit-animation: circle_left 5s linear infinite; */
  71. }
  72. @-webkit-keyframes circle_right{
  73. 0%{
  74. -webkit-transform: rotate(-135deg);
  75. }
  76. 50%,100%{
  77. -webkit-transform: rotate(45deg);
  78. }
  79. }
  80. @-webkit-keyframes circle_left{
  81. 0%,49%{
  82. opacity: 0;
  83. }
  84. 50%{
  85. opacity: 1;
  86. -webkit-transform: rotate(-135deg);
  87. }
  88. 100%{
  89. opacity: 1;
  90. -webkit-transform: rotate(45deg);
  91. }
  92. }
  93. </style>
  94. </head>
  95. <body>
  96. <div class="circle_process">
  97. <div class="wrapper right">
  98. <div class="circle rightcircle"></div>
  99. </div>
  100. <div class="wrapper left">
  101. <div class="circle leftcircle"></div>
  102. </div>
  103. </div>
  104. <div class="circle_process">
  105. <div class="show" id="show"></div>
  106. <div class="wrapper right">
  107. <div class="circle" id="rightcircle"></div>
  108. </div>
  109. <div class="wrapper left">
  110. <div class="circle" id="leftcircle"></div>
  111. </div>
  112. </div>
  113. </body>
  114. <script>
  115. var rightcircle = document.getElementById('rightcircle')
  116. var leftcircle = document.getElementById('leftcircle')
  117. var show = document.getElementById('show')
  118. function getTime() {
  119. var data = new Date()
  120. var second = data.getSeconds()
  121. show.innerHTML = second
  122. if (second <= 30) {
  123. rightcircle.style.cssText = 'transform: rotate(' + (-135+6*second) + 'deg)'
  124. leftcircle.style.cssText = 'transform: rotate(-135deg)'
  125. } else {
  126. rightcircle.style.cssText = 'transform: rotate(45deg)'
  127. leftcircle.style.cssText = 'transform: rotate(' + (-135+6*(second-30)) + 'deg);opacity:1'
  128. }
  129. }
  130. getTime();
  131. setInterval(function(){
  132. getTime()
  133. }, 1000)
  134. </script>
  135. </html>