How to add multi colored percentage bar that changes colors according to its progress?

Mizy

Jquery that i use to get the progress and add the percentage!

/* getting the percentage of the multi step verification */

$('.track').change(function(e) {
    update_percentage();
});
// supports any number of inputs and calculates done as %
function update_percentage() {
    var count = $('.track').length;
    var length = $('.track').filter(function() {
        return this.value;
    }).length;
    var done = Math.floor(length * (100 / count));
    $('.perc').text(done);

    $('.meter').width(done + "%");

        $(document).ready(function(){
        $a = done;
        $("#applicant_percentages").val($a);
    });
}

This is where the progress meter is shown in a bar as well as in percentage

<div class="progress-meter">
        <h5>Profile Strength <span class='perc'>0</span>%</h5>
        <span class="meter"></span>
        <br>
    </div>

CSS

.meter {
 display: inline-block;
  width: 0;
  height: 20px;
  margin-bottom: 10px;
  background-color:green;
}

Sample

I am getting the percentage of the number of input that are filled in a form! i have put the value i take into a progress bar .. but now what need the to change the colors of the progress bar once they reach certain values.

And sorry if i am unclear!

Jamiec

Given an array containing your required bands

let colors = [
    {max:20,color:'red'}, 
    {max:75,color:'yellow'},
    {max:100,color:'green'}];

You can find the right colour using Array.find based on the done amount:

var color = colors.find(x => x.max >= done).color;

And apply this to your progress bar using jQuery css

$('.meter').width(done + "%").css('background-color',color);

Live example below:

/* getting the percentage of the multi step verification */

$('.track').change(function(e) {
    update_percentage();
});

let colors = [{max:20,color:'red'}, {max:75,color:'yellow'},{max:100,color:'green'}];


// supports any number of inputs and calculates done as %
function update_percentage() {
    var count = $('.track').length;
    var length = $('.track').filter(function() {
        return this.value;
    }).length;
    
    var done = Math.floor(length * (100.0 / count));
    var color = colors.find(x => x.max >= done).color;
    
    $('.perc').text(done);

    $('.meter').width(done + "%").css('background-color',color);
}
.meter {
 display: inline-block;
  width: 0;
  height: 20px;
  margin-bottom: 10px;
  background-color:green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input class="track" type="text">
<input class="track" type="text">
<input class="track" type="text">
<input class="track" type="text">
<input class="track" type="text">
<input class="track" type="text">

<div class="progress-meter">
    <h5>Profile Strength <span class='perc'>0</span>%</h5>
    <span class="meter"></span>
    <br>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to add a progress bar?

How can I make a multi-colored segmented progress bar in wpf?

How to add progress bar?

multiple colors on progress bar with css or jquery based on width percentage

Add a percentage text to a static Ionic 4 progress bar

Progress bar: how to make color transition according to the progress?

Django admin how to show a progress bar in percentage

Angular Material Multi Progress Bar using multiple colors

How to add diamond marker in the progress bar percentage?

Is it possible to display different colors depending on percentage completion in progress bar?

Display multi-colors according to graph values in Vega bar charts

How can I make a progress bar that changes according to a specific input number variable?

How to change the progress bar colors based on the value

How to add progress bar icon in action bar?

How to add macro to progress bar

Progress bar with duration and percentage

ggplot2: How to plot barplot, where bars signify percentage and are colored according to percentage value?

How I can add progress bar with label with percentage of progress of upload in Alamofire 4.0

how to get progress bar percentage in a textblock to work?

How to create a multi-colored NativeScript BarSeries stacked bar chart

Calculating progress bar percentage

Pytube how to add a progress bar?

How can I align the icon according to the percentage of the progress bar?

How to design progress bar with text of its value?

How to show percentage along with progress bar in python?

How to change the text color for the percentage shown at the end of the progress bar

How to add progress bar

how to display the percentage of progress bar

How to add progress bar in powershell