What is the process for designing a progress bar with Bootstrap steps?

Is there a way to create a linear progress bar with circle markers indicating steps that reflect the user's progress? Take a look at the image below for reference:

.

I need to display 7 pages in total, numbered from 1 to 6.

My current progress bar does not change based on page navigation. I want it to update dynamically as the user clicks the 'Next' button and moves through each of the 7 pages.

Here is the code snippet I have been working on:

$(document).ready(function() {
  var i = 1;
  $('.progress .circle').removeClass().addClass('circle');
  $('.progress .bar').removeClass().addClass('bar');
  setInterval(function() {
    $('.progress .circle:nth-of-type(' + i + ')').addClass('active');

    $('.progress .circle:nth-of-type(' + (i - 1) + ')').removeClass('active').addClass('done');

    $('.progress .circle:nth-of-type(' + (i - 1) + ') .label').html('✓');

    $('.progress .bar:nth-of-type(' + (i - 1) + ')').addClass('active');

    $('.progress .bar:nth-of-type(' + (i - 2) + ')').removeClass('active').addClass('done');

    i++;

    if (i == 0) {
      $('.progress .bar').removeClass().addClass('bar');
      $('.progress div.circle').removeClass().addClass('circle');
      i = 1;
    }
  }, 1000);
});
body {
  font-family: 'Lato', sans-serif;
}
.progress {
  width: 1000px;
  margin: 20px auto;
  text-align: center;
}
.progress .circle,
.progress .bar {
  display: inline-block;
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 40px;
  border: 1px solid #d5d5da;
}
.progress .bar {
  position: relative;
  width: 80px;
  height: 6px;
  top: -33px;
  margin-left: -5px;
  margin-right: -5px;
  border-left: none;
  border-right: none;
  border-radius: 0;
}
.progress .circle .label {
  display: inline-block;
  width: 32px;
  height: 32px;
  line-height: 32px;
  border-radius: 32px;
  margin-top: 3px;
  color: #b5b5ba;
  font-size: 17px;
}
.progress .circle .title {
  color: #b5b5ba;
  font-size: 13px;
  line-height: 30px;
  margin-left: -5px;
}
/* Done / Active */

.progress .bar.done,
.progress .circle.done {
  background: #eee;
}
.progress .bar.active {
  background: linear-gradient(to right, #EEE 40%, #FFF 60%);
}
.progress .circle.done .label {
  color: #FFF;
  background: #66cccc;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .2);
}
.progress .circle.done .title {
  color: #444;
}
.progress .circle.active .label {
  color: #FFF;
  background: #0c95be;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .2);
}
.progress .circle.active .title {
  color: #0c95be;
}
.bar.done {
  background: #66cccc !important;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<div class="progress">
  <div class="circle done">
    <span class="label">1</span>
    <span class="title">0%</span>
  </div>
  <span class="bar done"></span>
  <div class="circle done">
    <span class="label">2</span>
    <span class="title">25%</span>
  </div>
  <span class="bar half"></span>
  <div class="circle active">
    <span class="label">3</span>
    <span class="title">50%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">4</span>
    <span class="title">75%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">5</span>
    <span class="title">100%</span>
  </div>
</div>

Answer №1

Showcasing half of the bar's progress can be achieved by dividing the current span.bar element into two smaller elements each with half the size.

Here is an illustration:

.progress .bar-half {
  width: 40px;
}
<span class="bar bar-half done"></span>
<span class="bar bar-half"></span>

You can then represent progress by adding the class done to the respective bar.

For your situation, you can simply set up a progress bar with a fixed progress in all of your HTML pages.

Below is a sample showing a bar that is half filled:

body {
  font-family: 'Lato', sans-serif;
}
.progress {
  width: 1000px;
  margin: 20px auto;
  text-align: center;
}
.progress .circle,
.progress .bar {
  display: inline-block;
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 40px;
  border: 1px solid #d5d5da;
}
.progress .bar {
  position: relative;
  width: 80px;
  height: 6px;
  top: -33px;
  margin-left: -5px;
  margin-right: -5px;
  border-left: none;
  border-right: none;
  border-radius: 0;
}
.progress .bar-half {
  width: 40px;
}
.progress .circle .label {
  display: inline-block;
  width: 32px;
  height: 32px;
  line-height: 32px;
  border-radius: 32px;
  margin-top: 3px;
  color: #b5b5ba;
  font-size: 17px;
}
.progress .circle .title {
  color: #b5b5ba;
  font-size: 13px;
  line-height: 30px;
  margin-left: -5px;
}
/* Done / Active */

.progress .bar.done,
.progress .circle.done {
  background: #eee;
}
.progress .bar.active {
  background: linear-gradient(to right, #EEE 40%, #FFF 60%);
}
.progress .circle.done .label {
  color: #FFF;
  background: #66cccc;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .2);
}
.progress .circle.done .title {
  color: #444;
}
.progress .circle.active .label {
  color: #FFF;
  background: #0c95be;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .2);
}
.progress .circle.active .title {
  color: #0c95be;
}
.bar.done {
  background: #66cccc !important;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<div class="progress">
  <div class="circle done">
    <span class="label">1</span>
    <span class="title">0%</span>
  </div>
  <span class="bar bar-half done"></span>
  <span class="bar bar-half"></span>
  <div class="circle">
    <span class="label">2</span>
    <span class="title">25%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">3</span>
    <span class="title">50%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">4</span>
    <span class="title">75%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">5</span>
    <span class="title">100%</span>
  </div>
</div>

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

Typescript Class Getting Vacant

When working with a specific setup in TypeScript, I encountered a situation where at runtime in JavaScript, I ended up with empty class objects. This occurred when two classes referenced each other, leading to one of them being empty within the scope of th ...

Ensure accuracy when converting to a float data type

My dilemma involves sending numerical values to a server using an AJAX call. For instance, numbers like 0.77, 100, and similar variations are being transmitted. However, upon reaching the server, the data is being interpreted differently - 0.77 as a double ...

Validating forms in ReactJS

I have developed a basic form validation feature for React. The inspiration for this project came from the following source: When I try to submit the form, input errors arise within the isValid function. I am seeking assistance in resolving this issue. A ...

Searching for mustache variables in HTML using regular expressions is a helpful way to

As I work on parsing template files in my code, one of my first tasks involves removing all Mustache variables in the template. The majority of these variables follow this structure: {{variable}}, {{#loop}}{{content}}{{/loop}}, {{^not}}{{/not}}, {{! comme ...

Removing an Entry from a MySQL Database with the Help of Ajax

I've encountered an issue with my code, preventing it from running successfully. While debugging my Ajax script using the Google Developer Tools, I noticed that the data parameter in my Ajax request contains the primary key (uid), but for some reason, ...

Bizarre text scenarios in JavaScript

I've come across something similar in certain libraries if ("testing" !== 'production') { "testing" !== 'production' ? warning(this instanceof Constructor, 'A React component is being called directly. Consider using ...

Can a layer be sliced to create a text-shaped cutout?

I want to achieve a cool text effect where the background is visible through the letters. I have explored options with background images and colors, but I haven't found any examples where the underlying layer is revealed. Is this even possible? Imag ...

Troubleshooting jQuery click event listeners and AJAX requests: Issue with second listener not functioning properly

There are two click listeners implemented on a page, one for a sub-navigation menu (which dynamically changes the list items in the menu) and another for a main menu (which dynamically changes the content in another section). <nav class="sub-nav"> ...

Is there a way to create dynamic documents in Firestore using Angular?

How can I use a dynamic ID to fetch the values of a document in Firestore? For example, if I have documents named document1 and document2 under the same collection, how can I specify a dynamic path with a dynamic document name to retrieve the specific do ...

Enhance Vaadin with custom validation and content mode options

Validation is needed for certain fields. The captions of the fields contain various formatting elements such as ", ", etc, with the option captionAsHtml="true". However, when using someField.addValidator(..., errorString), the error message displays both ...

tool for uploading and validating multiple file types

I have a file upload control for uploading multiple files. Here is an example: <ajaxToolkit:AsyncFileUpload ClientIDMode="Static" name="aa[]" BackColor="Azure" ForeColor="Black" OnClientUploadError="uploadError" OnClientUploadStarted="abc" ...

Mongoose not functioning correctly when attempting to remove items from an array that meet a certain condition

In my document, I have a property called weeks which is an Array containing Objects. [ { "time": [ "06", "00" ], "active": false, "reason": " ...

Is it possible to transform a class file into a function using hooks?

I have this React class that I want to convert into React hooks. I attempted to do so but ran into some issues. Here are the original and updated codes: class Parent extends React.Component { constructor(props) { super(props); this.state = { nam ...

Drag multiple objects in three.js

I created a 3D space using Three.js, similar to the example shown here. My goal now is to allow users to select and drag multiple objects simultaneously. I'm questioning whether I can modify the existing example to achieve this or if I need to start ...

Ways to successfully transfer an array containing numerous mesh entities

One task I need to accomplish is parsing an array that was created in a web worker back to the main thread. This particular array contains a large number of THREE.Mesh objects. However, when attempting to stringify this array using the following code: sel ...

Is the button not aligned properly with the email input field?

<div class="subscribe__form--action--btn"> <form action="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32545b5e5b5746545C5B5356477F54585850"> </a>" meth ...

Transforming a string into an object

I've been working on this code where my aim is to convert a string into an object and then display the data from an ajax call. However, it appears that using the string value in this way is not functioning as expected. var string = "first: 'Geor ...

Encountered an issue while building npm: "Error: Unable to locate module @restart/context

Lately, I've encountered an issue with npm build after upgrading to the latest version of react-bootstrap (1.0.0-beta.6). While creating an optimized production build... Failed to compile. Module not found: '@restart/context/forwardRef'. P ...

Guidelines on maintaining an active getSelection with JavaScript

I need help figuring out how to change the font size of selected text within a div without losing the highlight/selection when I click a button. Can someone assist me in keeping the text highlighted while also resizing it upon clicking the button? ...

The Javascript function was invoked, however the complete result was not yet delivered

I'm still a newbie when it comes to Meteor and Node.js, so what I'm struggling with might be a piece of cake for the more experienced developers out there. My task involves writing a script that aims to return the time 30 minutes into the future ...