I am trying to animate Bootstrap progress bar, but I'm not sure how to do that.
I got the value of the width but console.log(bar_width);
returns the width in px
but not %
as shown inline style="width:90%
.
I recreated a bootply with the code: BootStrap Progress Bar
HTML:
<!-- Skills Progress Bar -->
<section id="skills-pgr">
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="90"
aria-valuemin="0" aria-valuemax="100" style="width:90%">
<span>HTML/CSS</span>
</div>
</div>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="85"
aria-valuemin="0" aria-valuemax="100" style="width:85%">
<span>Photography</span>
</div>
</div>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="80"
aria-valuemin="0" aria-valuemax="100" style="width:80%">
<span>CMS</span>
</div>
</div>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="75"
aria-valuemin="0" aria-valuemax="100" style="width:75%">
<span>JavaScript/jQuery</span>
</div>
</div>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="60"
aria-valuemin="0" aria-valuemax="100" style="width:60%">
<span>Photoshop</span>
</div>
</div>
</section>
jQuery:
// Skills Progress Bar
$(function() {
$('.progress-bar').each(function() {
var bar_width = $(this).css('width'); // returns the css width value
var bar_value = $(this).attr('aria-valuenow');
console.log(bar_width);
console.log(bar_value);
$(this).animate({ value: bar_width }, { duration: 2000, easing: 'easeOutCirc' });
});
});
I'm assuming you want the progress to be animated from zero to the amount specified in
aria-valuenow
. You are almost there!style
attribute from each of the progress bars as that will instantly put them at the final amount.%
to thebar_value
to make it be recognized as a percentage. Without a unit it will be seen as a pixel value.animate
function needs to know which css property to animate. I've changedvalue
in your code example intowidth
to animate thewidth
propertyeaseOutCirc
easing function exists only in jQuery UI. I'm not sure if you had that as a resource in your Bootply, but I've added it here.In Bootstrap 3, it's very easy to animate progress bars. All you need to do, is change the width of your
.progress-bar
, like this :Just repeat the process whenever your width value needs to be updated, until the process bar reaches 100%.
A demo
(see also this Fiddle)
You could use setInterval timer and increase the width at some interval until it reaches a max width..
http://bootply.com/tC8sgQRwDD#