I'm looking to generate a semicircle progress bar using jQuery, any suggestions on how

Hi there! I'm looking to create a unique half circle design similar to the one showcased in this fiddle. Additionally, I want the progress bar to be displayed in a vibrant green color.

I've recently started learning about Jquery and would appreciate any guidance you can provide.

Here's the code snippet:

<div>
    <p>100%</p>
</div>

And here's the corresponding CSS:

div {
  height: 45px;
  width: 90px;
  border-radius: 90px 90px 0 0;
  -moz-border-radius: 90px 90px 0 0;
  -webkit-border-radius: 90px 90px 0 0;
  border: 5px solid red;
  border-bottom: none;
}

p { 
  text-align: center;
  padding: 20px 0;
}

You can access the fiddle here.

Answer №1

Utilize jQuery's .animate() function with the step method on custom values to manage the rotation of the CSS3 .bar element using transform: rotate

$(".progress").each(function(){
  
  var $bar = $(this).find(".bar");
  var $val = $(this).find("span");
  var perc = parseInt( $val.text(), 10);

  $({p:0}).animate({p:perc}, {
    duration: 3000,
    easing: "swing",
    step: function(p) {
      $bar.css({
        transform: "rotate("+ (45+(p*1.8)) +"deg)",
      });
      $val.text(p|0);
    }
  });
});
.progress{
  position: relative;
  margin: 4px;
  float:left;
  text-align: center;
}
.barOverflow{ 
  position: relative;
  overflow: hidden; 
  width: 90px; height: 45px; 
  margin-bottom: -14px; 
}
.bar{
  position: absolute;
  top: 0; left: 0;
  width: 90px; height: 90px; 
  border-radius: 50%;
  box-sizing: border-box;
  border: 5px solid #eee;     
  border-bottom-color: #0bf;  
  border-right-color: #0bf;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="progress">
  <div class="barOverflow">
    <div class="bar"></div>
  </div>
  <span>10</span>%
</div>

<div class="progress">
  <div class="barOverflow">
    <div class="bar"></div>
  </div>
  <span>100</span>%
</div>

<div class="progress">
  <div class="barOverflow">
    <div class="bar"></div>
  </div>
  <span>34</span>%
</div>

<div class="progress">
  <div class="barOverflow">
    <div class="bar"></div>
  </div>
  <span>67</span>%
</div>

P.S: You may not require JS since this can be achieved in pure CSS3, unless you need precise control over progress steps.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

a dedicated TypeScript interface for a particular JSON schema

I am pondering, how can I generate a TypeScript interface for JSON data like this: "Cities": { "NY": ["New York", [8000, 134]], "LA": ["Los Angeles", [4000, 97]], } I'm uncertain about how to handle these nested arrays and u ...

Acquiring HTML form data using JavaScript

Although it may seem trivial, I'm facing a challenge. I have an HTML form that is dynamically generated by JavaScript and populated with initial data fetched from the server. The form is displayed correctly with the pre-filled data. My goal is to allo ...

Error: Unable to access the property 'fontSize' as it is undefined

<!DOCTYPE HTML> <html> <head> <title>Interactive Web Page</title> <link id="mycss" rel="stylesheet" href="mycss.css"> <script> function resizeText(size) { va ...

A more sophisticated approach to button creation, such as utilizing a single HTML element

Trying to find a sleeker way to create the following HTML button. https://i.sstatic.net/Eanuy.png Currently using an <a href="..."> with 2 child <span> elements like this: - <a href=""> <span class="box_button">Read more</ ...

Prevent scale animation for a specific section of the icon using CSS

I need help in preventing the scale animation of the :before part of the icon class from occurring when the button is hovered. The current behavior is causing the arrow to look distorted on hover... Link to the code on Codepen HTML <div class="se ...

There was an issue encountered while parsing the JSON data - "SyntaxError: Unexpected token . was caught."

Encountering an error in Chrome while parsing JSON data. The JSON sample can be found at this link. It is valid JSON and the server is sending the correct Content-Type value (application/json). Uncaught SyntaxError: Unexpected token . Firefox shows a sli ...

Transferring data from an Excel spreadsheet into a structured table

I am interested in transferring specific columns of data from an excel sheet to an HTML table. My goal is to populate the table based on certain conditions rather than statically inputting fixed cells. For instance, if my excel sheet has columns for Name ...

Upon script load, a random item from an array will be displayed and recorded in a separate array

I'm working on a fun code project where I aim to display random animal names in different colors that change when a specific keyboard key is pressed. The challenge I'm facing is that the first random animal name in a random color only appears aft ...

Tips for gracefully organizing a sequence of requests/callbacks with the dojo framework?

My experience with dojo has been pretty good, but I still have some questions about dojo.Deferred as there are features that I haven't fully explored yet. While researching, I began to wonder if using a Deferred in the following scenario would be a be ...

What could be the reason for the three.js scene failing to render in my Svelte application?

Scene.svelte <!-- Start by binding a container, then add the renderer to this container onMount --> <script> import { onMount } from 'svelte'; import * as THREE from 'three'; let container; onMount(async () = ...

Does the react-google-login library utilize the services provided by Google Identity?

Currently incorporating the react-google-login library (https://www.npmjs.com/package/react-google-login/v/5.2.2) in my JavaScript codebase to grant users access to my website. Can anyone confirm whether this library utilizes "Google Identity Services" or ...

Transforming data with D3.js into a string representation

Recently, I stumbled upon a function called "stringify" that seems like a fantastic tool for converting flat data into a Json format. If this function lives up to its potential, it could potentially save me countless hours of writing recursive code in ASP ...

Converting a JSON file into an HTML table using PHP

I need help figuring out how to display JSON data in an HTML table. I have a script that successfully outputs my JSON content, but I'm struggling to format it into a table. Below is the code I have so far: <?php $dir = "/Apache24/htdocs/reservat ...

The UL list-style does not seem to be working properly on the Woocommerce checkout page

After creating my e-commerce website and implementing the woocommerce plugin to display products, I encountered an issue. The main menu pages are all showing up with the list-style, but the pages associated with the plugins are not displaying the list-styl ...

A guide on implementing arrow links in D3.js

i am struggling to add an arrow to one end of a link in my code. even though the links are functioning correctly, i can't seem to figure out how to draw arrows successfully. any assistance on how to implement this would be greatly appreciated. thank y ...

Error message: After using gulp-npm-dist to copy only the dependency modules, the node module was not

I'm currently exploring different methods to package only the necessary node_modules dependencies for my project. After some research, I came across gulp-npm-dist and created a gulpfile.js. var gulp = require('gulp'); var npmDist = requir ...

Issues with hover menu arise following relocation of primary menu

#header { height: 108px; width: 1140px; background-color: #faa220; position: relative; } #Logo2 { height: 108px; float: left; } #header links { height: 50px; float: left; list-style: none; padding-top: 10px; } #container { overflo ...

servlet responding unexpectedly to $ajax calls

Hey there, let's talk about the issue at hand... I've been keeping my "saved workouts" stored in Google Datastore as Text objects. When I pull up my saved workouts, the server sends back a bunch of JSON objects all packed into an Array. After pa ...

Verifying whether every value in the X array is present in the Y array or not

Currently, I am working with two arrays: const arrA = [1, 2, 3, 4, 5]; const arrB = [1, 2, 3, 4, 5, 6, 7, 8, 9]; My goal is to determine if all elements in array A exist in array B. Here are a few scenarios for better clarity: const arrA = [1, 2, 3, 4, ...

Is it possible for a malicious party to modify the src attribute within an iframe?

My website incorporates IFrame on a page, loading different pages based on server-side logic. As such, the source code appears like this when viewed: <iframe src="DeterminedOnServerSide.aspx" id="myFrame"> </iframe> I am curious if there is a ...