37

Is it possible to render indeterminate progress bar with Twitter Bootstrap (either v2 or v3) using either some build-in functionality or 3rd party plugin? I trued to google for it, but with no luck.

Example of I want to achieve:

progress bar

John Slegers
  • 38,420
  • 17
  • 182
  • 152
Max Romanovsky
  • 2,644
  • 5
  • 26
  • 36
  • 1
    Possible duplicate of [Indeterminate progress bar in HTML+CSS](http://stackoverflow.com/questions/7555181/indeterminate-progress-bar-in-htmlcss) – Daniel Cheung Sep 30 '16 at 05:19

6 Answers6

34

In bootstrap 2:

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="progress progress-striped active">
  <div class="bar" style="width: 100%;"></div>
</div>

In bootstrap 3:

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="progress progress-striped active">
  <div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
  </div>
</div>

In bootstrap 4:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

<div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>
</div>
thordarson
  • 4,684
  • 2
  • 15
  • 35
Cody
  • 2,189
  • 2
  • 16
  • 29
  • 25
    While an old answer, this is the top result when doing a google search for this, and this doesn't answer the question. The answer provides a normal progress bar, while the question asks for an indeterminate progress bar. Indeterminate progress bars have no known progress to display: http://en.wikipedia.org/wiki/Progress_bar – Will Eddins Mar 12 '14 at 18:19
  • 6
    Did you bother trying the code I provided? http://jsfiddle.net/CodyRank/pJ476/ It's pretty much a textbook example of an indeterminate progress bar. See also: http://goo.gl/iZRSzZ – Cody Mar 12 '14 at 19:04
  • 1
    I'll take back the downvote - I guess as long as it doesn't move from 100%, it looks close enough. I was expecting something more along the lines of a moving bar that wasn't just an animated 100%, but it looks like the mac indeterminate is exactly that. Windows tends to be the moving section. Sorry for ever doubting you! – Will Eddins Mar 12 '14 at 19:32
  • Neither of these worked for me. The first snippet gave me an empty progress bar, the second gave me a full one... neither animates in any way – Ortund May 17 '18 at 13:46
  • Not really... a new question would be more appropriate but I eventually got it working so no stress – Ortund May 23 '18 at 10:16
  • I added code for how to do this in bootstrap 4, since this answer is pretty old – Cody May 23 '18 at 17:14
28

If you want a CSS-only solution, here ya go:

HTML:

<div class="progress" style="position: relative;">
    <div class="progress-bar progress-bar-striped indeterminate">
</div>

CSS:

.progress-bar.indeterminate {
  position: relative;
  animation: progress-indeterminate 3s linear infinite;
}

@keyframes progress-indeterminate {
   from { left: -25%; width: 25%; }
   to { left: 100%; width: 25%;}
}

Here's a working version:

https://jsbin.com/dewikogujo/edit?html,css,output

Dave
  • 281
  • 3
  • 2
  • 4
    This is the best answer in my opinion, as it emulates the traditional Windows "marquee" bar. With a small HTML change, it works with Bootstrap 3 too: `
    `
    – romaricdrigon Feb 12 '19 at 11:23
  • This should be the accepted answer as it works out of the box with a Bootstrap progress bar. Also, the animation can be replaced with a more sophisticated one sould anybody want it. – beerwin Jul 16 '20 at 16:19
  • You are a legend! – Samuel Martins Nov 18 '20 at 17:26
19

Here's what I would do to get an indeterminate progress bar :

  • Use a striped, animated progress bar
  • Set it at 100%
  • Customize the animation speed
  • Add a text like "please wait" to inform the user that something is being processed
  • Add ellipses (...), using the css content property
  • Animate the ellipses using CSS in browsers that support this

Demo :

.progress {
    margin: 15px;
}

.progress .progress-bar.active {
    font-weight: 700;
    animation: progress-bar-stripes .5s linear infinite;
}

.dotdotdot:after {
    font-weight: 300;
    content: '...';
    display: inline-block;
    width: 20px;
    text-align: left;
    animation: dotdotdot 1.5s linear infinite;
}

@keyframes dotdotdot {
  0%   { content: '...'; }
  25% { content: ''; }
  50% { content: '.'; }
  75% { content: '..'; }
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="progress">
  <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
    <span>Please wait<span class="dotdotdot"></span></span>
  </div>
</div>

(see also this Fiddle)

John Slegers
  • 38,420
  • 17
  • 182
  • 152
  • this answer combined with Bootbox.js (http://bootboxjs.com) is what finally worked for me. t/y! – snerd Oct 25 '16 at 16:11
  • I used this answer with blockUI, worked like a charm – Carlo G Oct 26 '17 at 08:21
  • how do you render this based on submitting some processing and remove it after processing is completed? – tale852150 Nov 08 '17 at 22:50
  • 1
    @tale852150 : You just need to set the width of your progress bar at several steps of your processing. See [Bootstrap progress bar progression](https://stackoverflow.com/questions/18531013/bootstrap-progress-bar-progression/35988071) for a basic demo. – John Slegers Nov 09 '17 at 07:30
  • @JohnSlegers Appreciate the feedback. But this is an indeterminant progress bar. I need it to stop and show "Process Completed" (or go away completely) when my processing has completed. There is no progression per se involved. Or maybe I am just misunderstanding your feedback. :-) – tale852150 Nov 09 '17 at 14:06
  • @tale852150 : It's the same basic principle : you change your CSS based on the status of your process. If your process has only two statuses (eg. "in progress" & "completed"), just put a progress bar & a completion message at the same spot in your HTML code. Then, hide your completion message (`display : none`) while your process has status "in progress" and hide your progress bar while the status is "completed". This is also demonstrated by the same demo I referenced in my previous comment! ➡ Wait until the progress bar hits 100% to see the effect! – John Slegers Nov 09 '17 at 18:24
5

Old topic.. but I had to do this today. Here's what I did.

First, I used the Bootstrap dialog class as found here.

HTML fragment

<div id="progressDiv" class="progress">
    <div class="progress-bar progress-bar-striped active" 
        role="progressbar" 
        aria-valuenow="100" 
        aria-valuemin="0" 
        aria-valuemax="100" 
        style="width: 100%">
    </div>
</div>

JavaScript

var progress = $("#progressDiv").html();

BootstrapDialog.show(
{
    title: "Please wait...",
    message: progress
});

The resulting dialog is: (Note that the progress bar is animated)

enter image description here

This pops up up a modal dialog showing an animated bar.

Jonathan Lidbeck
  • 1,308
  • 1
  • 12
  • 14
James
  • 935
  • 2
  • 9
  • 11
1

I was unhappy with an animated, striped progress bar at 100%, so I wrote some CSS. Just add the class jkoop-progress-bar-indeterminate to your <div class="progress-bar .... That's it.

Tested with Bootstrap v4.5

.progress .jkoop-progress-bar-indeterminate.progress-bar-animated {
  animation: indeterminate 1s linear infinite alternate, progress-bar-stripes 1s linear infinite;
  width: 25% !important;
}

.progress .jkoop-progress-bar-indeterminate {
  animation: indeterminate 1s linear infinite alternate;
  width: 25% !important;
}

@keyframes indeterminate {
  0% {
    margin-left: 0;
  }
  100% {
    margin-left: 75%;
  }
}
<html>

<head>
  <title>Indeterminate Progress Bar</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js" integrity="sha384-LtrjvnR4Twt/qOuYxE721u19sVFLVSA4hf/rRt6PrZTmiPltdZcI7q7PXQBYTKyf" crossorigin="anonymous"></script>
</head>

<body style="margin: 20px;">
  <h1>Indeterminate Progress Bar</h1>

  <div class="progress">
    <div class="jkoop-progress-bar-indeterminate progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>
  </div>

  <p style="color:#888;text-align:right">Bootstrap v4.5.2</p>
</body>

</html>
jkoop
  • 29
  • 6
0

It's not pretty, but it gets the job done:

HTML:

<div class="progress" style="position: relative;">
    <div class="progress-bar progress-bar-striped active" style="position: relative; left: -180px; width: 180px">
</div>

Javascript:

setInterval(function() {
    var progress_width = $('.progress').width();
    var $progress_bar = $('.progress-bar');

    $progress_bar.css('left', '+=3');

    var progress_bar_left = parseFloat($progress_bar.css('left')+'');
    if (progress_bar_left >= progress_width)
        $progress_bar.css('left', '-200px');
}, 20);

Feel free to optimize your jQuery selectors a bit ;-)

Here's a working version:

https://jsbin.com/copejaludu/edit?html,js,output

Dave
  • 281
  • 3
  • 2