progresscircle.css 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Inspiration for this project found at:
  3. * https://markus.oberlehner.net/blog/pure-css-animated-svg-circle-chart
  4. * 1. The `reverse` animation direction plays the animation backwards
  5. * which makes it start at the stroke offset 100 which means displaying
  6. * no stroke at all and animating it to the value defined in the SVG
  7. * via the inline `stroke-dashoffset` attribute.
  8. * 2. Rotate by -90 degree to make the starting point of the
  9. * stroke the top of the circle.
  10. * 3. Using CSS transforms on SVG elements is not supported by Internet Explorer
  11. * and Edge, use the transform attribute directly on the SVG element as a
  12. * . workaround.
  13. */
  14. .circle-chart {
  15. width: 200px;
  16. height: 200px;
  17. }
  18. .circle-chart__circle {
  19. stroke: #00acc1;
  20. stroke-width: 2;
  21. stroke-linecap: square;
  22. fill: none;
  23. animation: circle-chart-fill 2s reverse; /* 1 */
  24. transform: rotate(-90deg); /* 2, 3 */
  25. transform-origin: center; /* 4 */
  26. }
  27. /**
  28. * 1. Rotate by -90 degree to make the starting point of the
  29. * stroke the top of the circle.
  30. * 2. Scaling mirrors the circle to make the stroke move right
  31. * to mark a positive chart value.
  32. * 3. Using CSS transforms on SVG elements is not supported by Internet Explorer
  33. * and Edge, use the transform attribute directly on the SVG element as a
  34. * . workaround.
  35. */
  36. .circle-chart__circle--negative {
  37. transform: rotate(-90deg) scale(1,-1); /* 1, 2, 3 */
  38. }
  39. .circle-chart__background {
  40. stroke: #efefef;
  41. stroke-width: 2;
  42. fill: none;
  43. }
  44. .circle-chart__info {
  45. animation: circle-chart-appear 2s forwards;
  46. opacity: 0;
  47. transform: translateY(0.3em);
  48. }
  49. .circle-chart__percent {
  50. alignment-baseline: central;
  51. text-anchor: middle;
  52. font-size: 5px;
  53. fill:#fff;
  54. }
  55. .circle-chart__subline {
  56. alignment-baseline: central;
  57. text-anchor: middle;
  58. font-size: 4px;
  59. fill: #799dff;
  60. }
  61. .success-stroke {
  62. stroke: #00C851;
  63. }
  64. .warning-stroke {
  65. stroke: #ffbb33;
  66. }
  67. .danger-stroke {
  68. stroke: #ff4444;
  69. }
  70. @keyframes circle-chart-fill {
  71. to { stroke-dasharray: 0 100; }
  72. }
  73. @keyframes circle-chart-appear {
  74. to {
  75. opacity: 1;
  76. transform: translateY(0);
  77. }
  78. }