S
S
Semyon Kataparov2016-03-19 19:08:20
css
Semyon Kataparov, 2016-03-19 19:08:20

2 progress bars in 1 and how to change their width depending on the number?

2 progress bars in 1 and how to change their width depending on the number?
That is, for example, I submit the number 9 and 1 and how to make the left side have 90 percent, and the right side 10?
Here is an example of an already made progress bar on bootstrap - https://gyazo.com/edf0f75162f5932f990408ebe7e0555d

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Ermolov, 2016-03-19
@truexizt1

We make a common div, the width of the sidebars will be calculated from its width.
jQuery

$(document).ready(function(){

// определяем левый и правый сайдбар
     var left = $("#left");
     var right = $("#right");

// задаем числа
     var a = 35;
     var b = 2;
     var sum = a+b;

// рассчитываем ширину. Я сделал это пропорцией, чтобы было понятно. Возможно стоить добавить округление.
     left.css("width", (a*100)/sum+"%");
     right.css("width", (b*100)/sum+"%");

  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question