What is the best way to keep progress bar line distinct from checkpoints?

https://i.sstatic.net/FxCzs.png

Struggling to create a progress bar with distinct checkpoints, here's my attempt:

<!DOCTYPE html>
<html>
<head>
<style>
  /* Styles for the elements */
  .outer-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
  }

  .progress-container {
    width: 80%;
    height: 5px;
    background-color: green;
    position: relative;
  }

  .car {
    width: 20px;
    height: 20px;
    background-color: red;
    border-radius: 50%;
    position: absolute;
    top: -10px;
    left: 0;
    transition: left 1s linear;
  }

  .checkpoint {
    width: 10px;
    height: 10px;
    background-color: #88CCDF;
    border-radius: 50%;
    position: absolute;
    top: -5px;
    margin-left: -5px;
  }

  .before-reached {
    background-color: #88CCDF;
  }

  .reached {
    background-color: yellow;
  }

  .passed {
    background-color: green;
  }
</style>
</head>
<body>

<div class="outer-container">
  <div class="progress-container">
    <!-- Checkpoints -->
    <div class="checkpoint before-reached" style="left: 5%;"></div>
    <div class="checkpoint before-reached" style="left: 25%;"></div>
    <div class="checkpoint before-reached" style="left: 45%;"></div>
    <div class="checkpoint before-reached" style="left: 65%;"></div>
    <div class="checkpoint before-reached" style="left: 85%;"></div>
    
    <!-- Car icon -->
    <div class="car"></div>
  </div>
</div>

<script>
  // JavaScript to move the car along the progress line
  const car = document.querySelector('.car');
  const checkpoints = document.querySelectorAll('.checkpoint');

  let currentCheckpointIndex = 0;

  function moveCarToNextCheckpoint() {
    if (currentCheckpointIndex < checkpoints.length - 1) {
      checkpoints[currentCheckpointIndex].classList.remove('before-reached');
      checkpoints[currentCheckpointIndex].classList.add('reached');

      currentCheckpointIndex++;
      const nextCheckpoint = checkpoints[currentCheckpointIndex];
      car.style.left = nextCheckpoint.style.left;
    } else {
      checkpoints[currentCheckpointIndex].classList.remove('before-reached');
      checkpoints[currentCheckpointIndex].classList.add('passed');
    }
  }

  // Initially set color of first checkpoint to yellow
  checkpoints[currentCheckpointIndex].classList.add('before-reached');

  // Move the car every 2 seconds
  setInterval(moveCarToNextCheckpoint, 2000);
</script>

</body>
</html>

The outcome didn't match the design vision: https://i.sstatic.net/cTZnz.png

I experimented with various approaches like adding lines after each point and adjusting margins, but none worked. Note that the JavaScript functionality simulates a "delivery tracking system."

Answer №1

My solution requires an additional element to be added to your list.

Essentially, we want the same circle you currently have but in white (or whatever the background color may be) and slightly larger than the checkpoint.

To achieve this, I have made the following adjustments:

  .checkpoint {
    width: 10px;
    height: 10px;
    background-color: #88CCDF; /* Set the color for the checkpoints */
    border-radius: 50%;
    position: absolute;
    left: 50%;
    top: 25%;
    margin-left: -5px; /* Adjusted to add space on both sides */
  }
  .checkpoint-container{
    background-color: rgb(255, 255, 255);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    position: absolute;
    top: -5px;
  }

    <div class="checkpoint-container" style="left: 5%;">
        <div class="checkpoint before-reached"></div>
    </div>

This setup will create a div that houses your checkpoint (the yellow dot). By making this div slightly larger than the yellow dot with a white background, it creates a gap when displayed

  /* Styling for the outer container */
  .outer-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh; /* 100% viewport height */
  }

  /* Styling for the progress container */
  .progress-container {
    width: 80%;
    height: 5px;
    background-color: green;
    position: relative;
  }

  /* Styling for the checkpoints */
  .checkpoint {
    width: 10px;
    height: 10px;
    background-color: #88CCDF; /* Specify the color for the checkpoints */
    border-radius: 50%;
    position: absolute;
    left: 50%;
    top: 25%;
    margin-left: -5px; /* Adjusted to add space on both sides */
  }
  .checkpoint-container{
    background-color: rgb(255, 255, 255);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    position: absolute;
    top: -150%;
  }

  .reached {
    background-color: yellow; /* Color for checkpoints when reached */
  }
<div class="outer-container">
  <div class="progress-container">
    <!-- Checkpoints -->
    <div class="checkpoint-container" style="left: 5%;">
        <div class="checkpoint before-reached"></div>
    </div>
    <div class="checkpoint-container" style="left: 25%;">
        <div class="checkpoint before-reached"></div>
    </div>
    <div class="checkpoint-container" style="left: 45%;">
        <div class="checkpoint before-reached"></div>
    </div>
    <div class="checkpoint-container" style="left: 65%;">
        <div class="checkpoint before-reached"></div>
    </div>
    <div class="checkpoint-container" style="left: 85%;">
        <div class="checkpoint before-reached"></div>
    </div>
  </div>
</div>

I have omitted the JS and Car from the snippet above, but demonstrated how the containers function to create a space

I hope this explanation proves helpful!

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

React page is not loading properly after refreshing, displaying unprocessed data instead

Hello everyone! I am currently working on developing an app using Node, React, and Mongoose without utilizing the CRA command, and I have also incorporated custom webpack setup. Initially, I was able to build everything within a single React page (App.jsx ...

Transform the response before sending it with the Hapi.js Proxy

Currently, I am in the process of testing out Hapi.js for a new project that is part of my current workload. My main objective is to initiate a request on my Hapi server which will then trigger another request on an external server using the Hapi proxy fun ...

Issues with Jquery datatable causing column header to overlap the table header

I am facing an issue with my datatable as the table is not displaying correctly. Could someone advise me on how to troubleshoot and fix this problem? Below is the code snippet in question: $(tbName).dataTable({ "sScrollX": "100%", "sScro ...

Incorporating Mediainfo.js into Angular 8: A Seamless Integration

I'm attempting to utilize Mediainfo.js for retrieving video information on the frontend of my Angular 8 project. However, I am encountering the following errors: GET https://192.168.25.177:4200/MediaInfoModule.wasm 404 (Not Found) wasm streaming compi ...

React-app size has grown larger post-deployment

I recently created my second app clone using React. I have noticed that after deployment, the size of the app increases. Everything looks normal on localhost:3000, but it significantly grows once deployed. Any assistance in resolving this issue would be gr ...

Having trouble converting TypeScript to JavaScript, and encountering difficulty locating the 'protractor' module

I'm facing an issue with compiling TypeScript to JavaScript because I can't find the module 'protractor'. Despite having Protractor, TypeScript, and Jasmine installed locally with their respective types. Here is the structure of my pro ...

Text font automatically adjusts size in Chrome on Android

It seems that when a paragraph of text reaches a certain length, Google Chrome on Android decides to resize the text and make it larger (which can cause some interesting results). I've noticed that on my website, about half of the p-tags stick to the ...

Customize your Angular UI Bootstrap Datepicker with unique buttons - here's how!

Currently, I have a datepicker with clear and close buttons. I tried using the append function to add more buttons to this datepicker, but it didn't work because the content is not loaded until we click the icon since it's a popup datepicker. Is ...

Managing the lifecycle of a background worker in JavaScript (Node.js) - start and stop operations

I have a JavaScript function in my code that I refer to as a 'worker' which checks if it is running and performs some tasks class Application { async runWorker() { while (true) { while (!this.isStarted) ...

What issue could be present in my JavaScript promise setup?

I'm currently working on developing my own Promise in JavaScript to enhance my comprehension of how Promises work. I've encountered a roadblock while trying to understand the .then method and I need some guidance: I came across the documentation ...

Maintaining fixed panels as you scroll through a centrally aligned layout

I am looking to create a layout with three divs set up as columns. The outer two will be for navigation and need to stay in place while the user scrolls, but the middle section will contain content that should scroll normally along with the page. I know t ...

What steps should I take to create a web application without any universal pages?

I have a question that I couldn't find an answer to on the internet. It may be simple, but I'm struggling with it. Basically, I am working on a web app where two users, user 1 and user 2, will answer some questions. After that, they will be show ...

Utilizing HTML5 Video Autoplay with AngularJS ng-show: A Comprehensive Guide

How can I implement a video using the HTML5 video tag with autoplay in an AngularJS web application? I attempted to use the following code: <video ng-show="condition" autoplay ng-src="{{video.src}}"></video> Upon loading the web application, ...

Nodemon is currently inactive: "[nodemon] clean exit - holding off restart until further changes"

After diligently following an online tutorial and double-checking my code against it, I am still unable to resolve the error. My code is attached for reference. Any assistance would be greatly appreciated! Index.js import app from "./server.js"; ...

Is the alert still displayed during a frozen UI, even when it is within a synchronous ajax call?

Here is the code snippet for implementing global AJAX functionality. jQuery(function (){ $(document).ajaxStop(function() { alert("stop"); }); $(document).ajaxStart(function() { al ...

Google Cloud Endpoints API Encounter 404 Error

Scenario Currently, my setup involves AppEngine Cloud Endpoints using a Bootstrap JavaScript UI along with a Google SQL Datastore. Issue The problem arises when the Javascript tries to call gapi.client.load and receives a 404 error. Surprisingly, the ...

What is the process for importing extensions and files in Visual Studio Code?

Nodejs development utilizing (--experimental-modules) Current visual studio code intelligence import example: import config from "./config"; However, it should be imported as: import config from "./config.js"; An error is encountered without the . ...

Tips for executing a function once data is received from the .subscribe() method in Angular 5

I am struggling to find a solution that works. I am currently subscribing to an observable in the following way: this.contentfulService.weekNumber .subscribe( (weekNumber) => { this.weekNumber = weekNumber; } ); Once the data is receiv ...

Is it possible to create a central hub for all routes in a large AngularJS application?

Developing a large angularjs application with the intention of utilizing require.js for lazy-loading additional modules. The main question at hand is whether to create a comprehensive route.js file containing all the routes to other modules, or if each mod ...

Is there a universal method to determine if a user is currently active in an input field or other contenteditable element?

Currently, I am working on implementing keyboard shortcuts similar to Gmail or vim using the j/k keys to navigate through a list. I have achieved this by attaching a keydown event listener directly to the document that detects when the user presses either ...