Bootstrap progress bar loading does not function properly

I have a progress bar on my page with three parts: progress-bar-success, progress-bar-warning, and progress-bar-danger. I would like each part of the progress bar to complete sequentially, starting with progress-bar-success, then progress-bar-warning, and finally progress-bar-danger.

I am having trouble identifying what is causing the incorrect behavior in my code.

You can find my code here: JSFIDDLE

Any suggestions on how I can resolve this issue?

EDIT:

I would like the style of each progress bar to be similar to this example: bootply

Answer №1

These are the key issues in your initial code:

  • The width of the progress bar div should be updated to show progress, not the width of the bar element.
  • The progress bar div is independent of the container1 div's width because it floats (you can verify this by inspecting the container in your browser and noticing its lack of height) and is designed to work in conjunction with the .progress class.

Below is a corrected version of your code for reference: http://jsfiddle.net/436Qz/30/

HTML:

<div class="person-info col-xs-12 col-sm-8">
     <div class="progress progress-striped active">
         <div id="1" class="progress-bar progress-bar-success" role="progressbar"  aria-valuemin="0" aria-valuemax="100">
             <span class="sr-only">33.33% Complete (success)</span>
         </div>
     </div>
     <div class="progress progress-striped active">
         <div id="2" class="progress-bar progress-bar-warning" role="progressbar" aria-valuemin="0" aria-valuemax="100">
             <span class="sr-only">33.33% Complete (warning)</span>
         </div>
     </div>
     <div class="progress progress-striped active">
         <div id="3" class="progress-bar progress-bar-danger" role="progressbar" aria-valuemin="0" aria-valuemax="100">
             <span class="sr-only">33.33% Complete (danger)</span>
         </div>
     </div>
</div>

JS:

$(document).ready(function(){
    var $bar = $('.progress-bar#1');
    var progress = setInterval(function() {
        if ($bar.width()<260) {
            $bar.width($bar.width() + 26);
        }
        $bar.text(Math.floor($bar.width() / 2.6) + "%");
        if ($bar.width()>=260) {
            $bar.parent().removeClass("active");
            if ($bar.is("#3")) {
                return clearInterval(progress);
            }
            $bar = $bar.parent().next().children(".progress-bar");
        }
    }, 520);
});

CSS:

.person-info {
    margin-top: 40px;
    padding-left: 0px !important;
    padding-right: 0px !important;

}
.progress{
    width: 260px;
}

Answer №2

If you're interested in implementing a stacked progress bar, feel free to check out my example here: http://jsfiddle.net/436Qz/25/

HTML Code:

<div class="progress">
  <div class="progress-bar progress-bar-success" style="width: 0%">
    <span class="sr-only">35% Complete (success)</span>
  </div>
  <div class="progress-bar progress-bar-warning" style="width: 0%">
    <span class="sr-only">20% Complete (warning)</span>
  </div>
  <div class="progress-bar progress-bar-danger" style="width: 0%">
    <span class="sr-only">10% Complete (danger)</span>
  </div>
</div>

JavaScript Code:

$(document).ready(function(){

    var progress = setInterval(function() {
        var $successBar = $('.progress-bar-success');
        var $warningBar = $('.progress-bar-warning');
        var $dangerBar = $('.progress-bar-danger');

        if($successBar.width() < 160) {
            $successBar.width($successBar.width()+20);
        } else {
            if($warningBar.width() < 160) {
                $warningBar.width($warningBar.width()+20);
            } else {
                if($dangerBar.width() < 160) {
                    $dangerBar.width($dangerBar.width()+20);
                } else {
                    $dangerBar.width(160);
                }
            }
        }
    }, 100);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating the text of an element will occur only when the specified condition has been met

I am trying to dynamically change the text within the <span data-testid="recapItemPrice">ZADARMO</span> element from 'ZADARMO' to 'DOHODOU' only when the text inside the parent element 'INDIVIDUÁLNA CENA PREP ...

Firefox does not support jQuery AJAX functionality, unlike Internet Explorer where it works smoothly

Can anyone help me figure out how to ensure that this code works smoothly on both IE and Firefox? The confirm prompts are functioning in Firefox, but the AJAX request isn't triggering. According to Firebug, there's an error at line 9631 of jquery ...

The HR tag does not display anything following the mailing

Struggling to design a newsletter template with different lines for each product using the HR tag. However, none of my attempts with divs, tables, or CSS properties have been successful. The template looks fine in Chrome, but when sent to the provider, th ...

Using an ajax call to dynamically generate an array for jquery autocomplete feature

Struggling to implement a jQuery UI autocomplete feature using data from a database via an AJAX call. Having difficulty figuring out how to pass the table of values to the autocomplete function. $( document ).ready(function() { $.ajax({ url ...

Creating a tooltip with a left arrow and a bordered design

I am looking to create a tooltip that displays its content after clicking on the tooltip tip icon. Currently, it only works on hover, but I want it to be clickable and mobile responsive. Desktop design should resemble: https://i.sstatic.net/FQPyt.png Mob ...

Prevent a div from sliding up when a certain element is in view

Here is the issue I am facing: I want the top div to slide up or down only when the mediaPlayerWrapper is present, and not when the content_text is visible. Both are generated using Ajax and PHP, but only one exists at a time. The code below works correctl ...

Error in TypeScript while running the command "tsd install jquery" - the identifier "document" could not be found

Currently, I am facing an issue with importing jQuery into my TypeScript project. In order to achieve this, I executed the command tsd install jquery --save, which generated a jquery.d.ts file and added /// <reference path="jquery/jquery.d.ts" /> to ...

What do we need to ensure that the ajax server response is executed as intended in the jQuery ajax post function?

The jQuery script provided here returns the following string: '#prayer_date'.html("03/19/1968"); However, it remains unexecuted because the function does not interact with the data variable. To make sure the above result is executed within the ...

Tips on changing the outline color by clicking

I'm working on a simple code where I need to change the outline color when a user clicks on a text field. <input type="text" id="box1" /> <input type="password" id="box2" /> <input type="email" id="box3" /> <input type="submit" ...

To display the user's input value in the console log upon clicking

Having trouble displaying the user's input value in the console when the button is clicked. function submit(){ var userInput = document.getElementById('input_text').value; console.log(userInput); } ...

Combining various fields to showcase in autocomplete with AJAX on cakephp

I am currently facing an issue with my autocomplete functionality, as it only displays the first name of the user. I would like to concatenate the first name, last name, and other details. How can I modify the code below to achieve this? <script type=" ...

Enhance User Experience with JQuery Autocomplete for Internet Explorer 8 Using ASMX Web Services

Help Needed! I have been trying to implement a Web Service (ASMX) file on my website. When I access and query the page, I receive the desired results. The problem arises when I attempt to add autocomplete functionality to a textbox in my ASP.NET applicati ...

Trigger a function upon the addition of a class to a div element | Execute AnimatedNumber()

Is there a way to trigger a function when a specific div receives a certain class? I have an animated div that only appears when scrolling, and once it's visible, it gains the class "in-view". I want to execute a function every time this div has the ...

Tips for automating file uploads in HTML

I am having trouble filling the <input type="file"> element programmatically when trying to upload a file using a form. Can someone please provide me with guidance on how to accomplish this task? The method does not matter, I just want to achieve m ...

Modifying the calendar from a 7-day week to a 5-day week

I am currently in the process of developing a 7-day calendar (Sunday to Saturday) which is functioning well. However, I am interested in adding an option to switch it to a 5-day calendar (Monday to Friday). I was wondering if there is a way to modify the e ...

Auto-selecting the first item in a CSS menu when the switcher is tapped on mobile devices

Struggling with a responsive CSS menu on my website, . The switcher on mobile seems to automatically click the first item in the menu (Home) as I open it, redirecting me instantly. When setting the link to "#" everything is fine, but then I lose the home l ...

What are alternative methods for creating a table layout without relying on traditional table elements?

Is there a way to eliminate tables from my code and achieve the same layout in the name of progress and learning? Here is an example of the table I currently have: <table cellspacing="0px"> <tr> <td> <img src= ...

Can anyone help me get my carousel to work properly?

I am facing a carousel problem in my personal exercise project. I have gathered HTML, CSS, and JavaScript from the internet and am attempting to integrate them all together. //Sidebar script start $(document).ready(function () { var trigger = $(&apo ...

Clicking a button in jQuery to load the Pagemethods

<script type="text/javascript"> $(document).ready(function() { $('#loadbtn').click(function() { // can 't load opts = { title: 'ABCD', series: [{ ...

When using JavaScript to dynamically load canvases and create drawing contexts within a function, the context may suddenly disappear

Currently, I am modifying the canvases displayed through ajax calls and also updating what is drawn on each canvas. The primary issue I am facing is that my main drawing function fails on getContext and there are some unusual behaviors such as missing canv ...