Maison > interface Web > tutoriel CSS > Comment créer une barre de progression circulaire en pourcentage avec SVG et JavaScript ?

Comment créer une barre de progression circulaire en pourcentage avec SVG et JavaScript ?

Linda Hamilton
Libérer: 2024-11-15 13:11:02
original
777 Les gens l'ont consulté

How to Create a Circular Percent Progress Bar with SVG and JavaScript?

Creating a Circular Percent Progress Bar

To create a circular percent progress bar like the one seen in the mockup, consider using SVG due to its flexibility in creating rounded shapes.

SVG Code:

<svg viewbox="0 0 100 100">
  <circle cx="50" cy="50" r="45" fill="#FDB900"/>
  <path fill="none" stroke-linecap="round" stroke-width="5" stroke="#fff"
        stroke-dasharray="251.2,0"
        d="M50 10
           a 40 40 0 0 1 0 80
           a 40 40 0 0 1 0 -80">
    <animate attributeName="stroke-dasharray" from="0,251.2" to="251.2,0" dur="5s"/>           
  </path>
  <text>
Copier après la connexion

CSS:

body {
  text-align: center;
  font-family: 'Open Sans', sans-serif;
}

svg {
  width: 25%;
}
Copier après la connexion

JavaScript (Optional):

To animate the progress and increment the percentage, use the following jQuery code:

var count = $(('#count'));
$({ Counter: 0 }).animate({ Counter: count.text() }, {
  duration: 5000,
  easing: 'linear',
  step: function () {
    count.text(Math.ceil(this.Counter)+ "%");
  }
});
Copier après la connexion

Result:

The SVG code will create a circular progress bar with a yellow background and white progress indicator. The JavaScript animation will increment the percentage displayed in the center of the progress bar from 0 to 100% over 5 seconds.

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal