Twitter Bootstrap's buttons have a nice Loading...
state available.
The thing is that it just shows a message like Loading...
passed through the data-loading-text
attribute like this:
<button type="button" class="btn btn-primary start" id="btnStartUploads"
data-loading-text="@Localization.Uploading">
<i class="icon-upload icon-large"></i>
<span>@Localization.StartUpload</span>
</button>
Looking at Font Awesome, you see that there's now an animated spinner icon.
I tried to integrate that spinner icon when firing an Upload
operation like this:
$("#btnStartUploads").button('loading');
$("#btnStartUploads i").removeAttr('class');
$("#btnStartUploads i").addClass('icon-spinner icon-spin icon-large');
but this had no effect at all, that is, I just see the Uploading...
text on the button.
Is it possible to add an icon when the button is in the Loading state? Looks like somehow Bootstrap just removes the icon <i class="icon-upload icon-large"></i>
inside the button while in the Loading state.
Here's a simple demo that shows the behavior I describe above. As you see when it enters the Loading state the icon just disappears. It reappears right after the time interval.
Here's my solution for Bootstrap 4:
Check it out on JSFiddle
Simple solution for Bootstrap 3 using CSS3 animations.
Put the following in your CSS:
Then just add the
spinning
class to aglyphicon
while loading to get your spinning icon:Based on http://www.bootply.com/128062#
To make the solution by @flion look really great, you could adjust the center point for that icon so it doesn't wobble up and down. This looks right for me at a small font size:
If you look at the bootstrap-button.js source, you'll see that the bootstrap plugin replaces the buttons inner html with whatever is in data-loading-text when calling
$(myElem).button('loading')
.For your case, I think you should just be able to do this:
There's now a full-fledged plugin for that:
http://msurguy.github.io/ladda-bootstrap/