Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现圆形环状进度条 #203

Open
Sunny-117 opened this issue Nov 3, 2022 · 1 comment
Open

实现圆形环状进度条 #203

Sunny-117 opened this issue Nov 3, 2022 · 1 comment

Comments

@Sunny-117
Copy link
Owner

No description provided.

@huccct
Copy link

huccct commented May 5, 2023

<!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>Document</title>
    <style>
      .circle {
        fill: none;
        stroke: #7c83fd;
        stroke-width: 8;
        stroke-dasharray: 314;
        stroke-dashoffset: 314;
        stroke-linecap: round;
        transition: all 1s;
      }
      .text {
        font-size: 20px;
      }
      .percent {
        font-size: 10px;
      }
    </style>
  </head>
  <body>
    <svg>
      <circle
        class="circle"
        cx="80"
        cy="80"
        r="50"
        stroke="#7c83fd"
        transform="rotate(-90 80 80)"
      ></circle>
      <text x="80" y="85" fill="#6b778c" text-anchor="middle">
        <tspan class="text">0</tspan>
        <tspan class="percent">%</tspan>
      </text>
    </svg>
  </body>
  <script>
    let progressLen = 314;
    const textDom = document.getElementsByClassName('text')[0];
    const circleDom = document.getElementsByClassName('circle')[0];

    setPercent = num => {
      if (num > 100) return;
      circleDom.style['stroke-dashoffset'] = progressLen - (progressLen / 100) * num;
      textDom.innerHTML = num;
    };

    let i = 0;
    setInterval(() => {
      i += Math.floor(Math.random() * 5);
      if (i >= 100) i = 100;
      setPercent(i);
    }, 250);
  </script>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants