I’m using Twitter Bootstrap to build my web page.
I have this HTML code:
<div class="btn-group">
<button type="button" class="btn btn-success">Connect</button>
<button type="button" class="btn btn-success dropdown-data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><a href="#"> Connect 1</a></li>
<li role="separator" class="divider"></li>
<li><a href="#"> Connect 2</a></li>
</ul>
</div>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div>
</div>
<div class="alert alert-success" role="alert">Well done! You successfully connected. <a href="#step2" class="alert-link">Next</a></div>
I want to animate the progress bar from 0 to 100% when user push the connect button or push the dropdown button (one of two) and when the progressbar reach 100% the script show the alert previously hidden.
5
Answers
The bootstrap progress bar is animated by default. When you set the progress value to a new value it will cause the the bar to animate. You just need to set the value:
Try this code:
Taken this example from:
http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-progress-bars.php
http://www.tutorialrepublic.com/html-reference/html5-progress-tag.php
This is all it takes to create an animated progress bar :
This particular code will animate the progress bar from the current value to a value of 80%.
A demo
(see also this Fiddle)
In bootstrap v4 the progress bar animation is not by default anymore.
You can add transition-duration to the progress bar element to slow down the transition from 0 to the new width.
I know this was old enough.
But try code below, it should help you to animate more than one progress bar (if you happen to use more than one within a page).
Everytime you add progress bar, simply add another
execProg()
with desired width and its respectiveid