Animating circles with CSS to display percentages

Currently, I have a circle displaying text in the center as shown in this fiddle (JSFIDDLE http://jsfiddle.net/874jgh4v/2/). Now, my requirements are:

  1. I want to animate the outer white border based on a percentage. For example, if the percentage is 50%, then I need to display the border around half of the circle.

  2. I also want to show the percentage value on hover with some animation effects. For instance, only when hovering over the circle should the text "50%" appear.

.wrapper{padding:30px;}

.circle{
    border-radius: 50%;
    background:#32a500;    
    box-shadow: 0px 0px 0px 16px  #f1f1f1;
    border: 16px solid #f9f9f9;
    width:220px;
    height:220px;
    box-sizing:border-box;
}

.circle:hover {
     background:red;    
}
<div class="wrapper">
    <div class="circle">
        <p>Total ROE's</p>
        <p>300</p>
        <p>70%</p>
     </div>
</div>
Any assistance on achieving this would be highly appreciated! Additionally, I prefer to accomplish this without using any external libraries and the percentages should support decimal points up to two places.

Answer №1

Here is a suggested solution:

HTML

<span class='Progress'>
    <div class="Bar">
        <div class="Outer">
            <div class="Fill"></div>
        </div>
        <div class="Draw"></div>
        <div class="Status"><span></span></div>
    </div>                
</span>

CSS

.Progress {
    position: absolute;
    left: 25%;
    bottom: 30%;
}

.Progress .Bar {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: #E5E5E5;
    position: relative;
}

.Progress .Bar .Outer {
    content: "";
    position: absolute;
    border-radius: 50%;
    left: calc(50% - 35px);
    top: calc(50% - 35px);
    width: 70px;
    height: 70px;
    clip: rect(0, 70px, 70px, 35px);
}

.Bar .Outer .Fill {
    content: "";
    position: absolute;
    border-radius: 50%;
    left: calc(50% - 35px);
    top: calc(50% - 35px);
    width: 70px;
    height: 70px;
    clip: rect(0, 35px, 70px, 0);
    background: #00A0E3;
    transform: rotate(60deg);
}

.Progress .Bar .Draw {
    content: "";
    position: absolute;
    border-radius: 50%;
    left: calc(50% - 53.84615px/2);
    top: calc(50% - 53.84615px/2);
    width: 53.84615px;
    height: 53.84615px;
    background: #fff;
    text-align: center;
    display: table;
}

.Progress .Bar .Status {
    display: table-cell;
    vertical-align: middle;
    position: absolute;
    margin-left: -100px;
    margin-top: -10px;
    width: 200px;
    height: 200px;
    left: 50%;
    top: 50%;
    text-align: center;
}

.Progress .Bar .Status > span {
    font-size: 14px;
    font-weight: bold;
    color: #00A0E3;
}

.Progress .Bar.halfway {
    background-color: #00A0E3;
}

.Progress .Bar.halfway .Outer {
    clip: rect(0, 35px, 70px, 0);
}

.Progress .Bar.halfway .Outer .Fill {
    clip: rect(0, 70px, 70px, 35px);
    background: #E5E5E5;
}

.Progress .Bar.complete.halfway,
.Progress .Bar.complete .Fill {
    background-color: #8cd64c !important;
}

Javascript/JQuery:

$('document').ready(function() {

    var progress = function(perc) {

        perc = Math.round(perc * 100) / 100; // 2 decimal places

        var $bar = $('.Progress .Bar'), 
            $fill = $('.Progress .Bar .Outer .Fill'),
            $status = $('.Progress .Bar .Status span');

        $bar.removeClass("halfway").removeClass("complete");

        // outer bar
        if (perc >= 50) $bar.addClass("halfway");
        if (perc >= 100) $bar.addClass("complete");

        // progress bar
        var degrees = 360 * perc / 100;
        $fill.css({
          "WebkitTransform": 'rotate(' + degrees + 'deg)',
          "-moz-transform": 'rotate(' + degrees + 'deg)'
        });

      // status
        $status.html(perc);
    }

    // Test it!
    progress(10);
    setTimeout(function() { 
      progress(50); 
      setTimeout(function() { 
        progress(100); 
      }, 2000);
    }, 2000);

});

View the CodePen example

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

Code to achieve smooth scrolling from a hyperlink to a specific div element

<div style="border-radius: 10px; border: 2px solid #a1a1a1; padding: 10px 20px; width: 94%;"> <ul> <li>Listing of course details by country <ul> <li><a href="#bdpindia">India</a></li> <li><a href="#b ...

Updating the URL-path in the Angular file-upload module: A step-by-step guide

When working on my project, I came across a helpful module that I use from https://github.com/nervgh/angular-file-upload. It functions well when the URL is set during initialization. However, I encountered an issue when trying to change the URL after the ...

Any suggestions on how to customize the tawk.to positioning within a Next Js script?

I've been attempting to adjust the positioning of the Tawk.to Sticky button on my Next js website using CSS, but it doesn't seem to be working. Below is the script within the Next Js script tag: <Script dangerouslySetInnerHTML={{ __html: ` ...

Shuffle the contents of various div elements, conceal one, reveal another

I am currently working with a menu that uses the loadContent function to load pages into the #main div. This allows me to change the content of the page while keeping the menu intact. <ul> <li class="page1" onclick="loadContent('page1.php ...

Validating a request model against the schema defined in an OpenAPI 3 (Swagger) specification in NodeJS: A comprehensive guide

I am searching for a tool or framework that can validate the model of incoming requests against a schema defined in the Swagger documentation. ...

Save geometric shapes data in the SQLite database

How do I go about storing polygon data in an SQLite database? Important: I am utilizing the Cordova plugin. polygon: Point[]; interface Point { x: number; y: number; } https://i.sstatic.net/5EYf2.png ...

Tips for positioning a div next to an input box when it is in focus

I am working on a scenario where I have used CSS to extend the search box when focused. The idea is that when the search box is focused, it should decrease in size and a cancel button should appear next to it. This is the CSS code I am using: .clrble .fr ...

Transforming the string attribute of an object within a JavaScript array through mapping

Here is an array of objects: { "attr1": 123, "attr2": "a.end", }, { "attr1": 123, "attr2": "b.start", } The task is to remove the first part of the attr2 string up to and including the '.& ...

Deleting an item from an array using Vue.js

1. How can I remove a link using the method from a Vue.js component? Please help me troubleshoot this error: 'method splice is undefined' is showing up in console. Adding a link when inserting a message is not an issue, but removing it seems impo ...

At what point does angular2 @output get resolved?

Click on this link Here is the HTML code snippet: <chart [options]="options" (load)="saveGraphInstance($event.context)"></chart> <div (click)="switchGraph()">switch</div> <div (click)="showLoadingForce()">show loadin ...

Tips for keeping your navigation menu fixed at the top of the page as you scroll

I successfully created a navigation menu using ul > li. Currently, the menu is positioned in the center of the page. My goal is to make the menu stay at the top of the page only while scrolling. I know I can achieve this using css .menu { positi ...

Option in the dropdown menu will not appear on the user interface if the data contains the "&" sign

Below is an example dataset I'm using for my dropdown selection: [ { "value":"example1", "name":"example name 1" }, { "value":"example2", "name":"example & name 2" ...

Is there a simple way to set the form inputs to right-to-left without excessive duplication?

Is there a way to apply the right-to-left (RTL) direction to a form without duplicating code for every input, based on the locale of the language being used? Can the locale be changed in CSS to make the form RTL more efficiently? For example: <div ...

The Firebase read counts are increasing rapidly, even during times of inactivity

Explaining the issue I'm facing in detail, I recently embarked on developing my first larger project, a project management app using React. Everything was progressing smoothly until I started working on the task addition feature and updating graphs w ...

JavaScript and PHP/HTML template engine technology

I've recently discovered the jQuery template engine and am intrigued by its potential. It seems to be very efficient for ajax calls, as the data exchange is minimized. However, when I initially load my application using only PHP and HTML to display ...

Using JavaScript to conceal the browser's interface leads to a flaw with the position: fixed property specifically

Check out my website: On this site, there is a fixed position div #nav. In order to optimize the site for mobile, I am using JavaScript to hide the browser's chrome. Here's the code snippet: setTimeout(function() { window.scrollTo(0, 1) }, 10 ...

Is it possible to adjust the width of the comment box on the Facebook "Like" button?

Is there a way to set the width of the comment box that appears after clicking the Facebook "Like" button? I know how to adjust the width of the button itself and related content, but can't find any options for the comment box: I've tried overri ...

Organize the Div elements in the form of a message

Here is the code I am working with: https://jsfiddle.net/bdqgszv5/1/ This is the same code without jsfiddle: <section id="aussteller" class="row separated"> <div class="section-header text-center"> <h2& ...

Arrange objects in dropdown menu to line up

I'm currently working on a dropdown menu and I have a specific requirement – the menu should always be split into two columns and be able to span multiple lines. However, I've encountered an issue where the columns are not aligned properly, cau ...

Linking the value of an expression to ngModel

There is a specific scenario where I need the ng-model property to bind to a value retrieved from the database as part of the business logic. To illustrate this concept, I have set up an example function TodoCtrl($scope) { $scope.field1 = "PropertyFr ...