Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating Bootstrap progress bar width with jQuery

Tags:

I want to animate a progress bar's width from 0% to 70% over 2.5 seconds. However, the code below immediately changes the width to 70% after a 2.5 second delay. What am I missing?

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

JSFiddle: http://jsfiddle.net/WEYKL/

like image 338
user3088077 Avatar asked May 09 '14 22:05

user3088077


2 Answers

The problem is in default Bootstrap transition effect, which animates any update of the width property.

If you switch it off with supressing the corresponding style, it will work fine, e.g.:

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

DEMO: http://jsfiddle.net/WEYKL/1/

like image 186
VisioN Avatar answered Oct 12 '22 10:10

VisioN


So, it makes more sense to adjust the transition effect via CSS or jQuery.

.progress-bar {     -webkit-transition: width 2.5s ease;     transition: width 2.5s ease; } 

And just change the width value.

$(".progress-bar").css('width', '70%'); 
like image 42
daVe Avatar answered Oct 12 '22 09:10

daVe