Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML, CSS & JS Animate Multiple Progress bars

So I'm trying to animate multiple progress bars on one page, here is the HTML for my progress bars:

<div class="col-md-5">
  <p>HTML & CSS</p>
  <div class="progress progress-striped active">
    <div class="progress-bar progress-bar-danger" style="width: 50%;"></div>
  </div>
  <p>C#</p>
  <div class="progress progress-striped active">
    <div class="progress-bar progress-bar-danger" style="width: 20%;"></div>
  </div>
  <p>WordPress</p>
  <div class="progress progress-striped active">
    <div class="progress-bar progress-bar-danger" style="width: 30%;"></div>
  </div>
  <p>Photoshop</p>
  <div class="progress progress-striped active">
    <div class="progress-bar progress-bar-danger" style="width: 20%;"></div>
  </div>
</div>

I am also using this code in my CSS Styling

.progress.active .progress-bar {
   -webkit-transition: none !important;
   transition: none !important;
 }

And this is my JS function:

$(".progress-bar").animate({width: "10%"}, 2500);

Using this, all 4 bars are animated, but I'd like to animate each bar with a different value.

like image 507
Tom Withers Avatar asked Nov 01 '22 00:11

Tom Withers


1 Answers

You can target the individual bars using .eq() which takes an index as a parameter to specify which bar you want.

$(".progress-bar").eq(0); // First bar
$(".progress-bar").eq(1); // Second bar

From here, just call the animate method on the selected element. Storing the initial $(".progress-bar") call is also considered good practice.

var $bars = $(".progress-bar");
$bars.eq(0).animate({width: "10%"}, 2500);
$bars.eq(1).animate({width: "5%"}, 2500);
like image 200
SeinopSys Avatar answered Nov 12 '22 17:11

SeinopSys