Project 2 - Progress Steps

 About:

    In this Blog , I will be designing Progress Steps. I am implementing this using simple Html, CSS and JavaScript , we are not using any frameworks.

For this, I am using three files here, You can find the source for this and for output , you can refer to the video below.

Initially I took numbers to show progress steps and we can also use images for this, I will be showing the implementation with both ways. If you want to use images, you have to create Assests folder and can save images in this folder.

Source Code:

index.html -

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <title>Progress Steps</title>
  </head>
  <body>
    <div class="container">
      <div class="progress-container">
        <div class="progress" id="progress"></div>
        <!-- you can use these to get images
        <div class="circle active borderr"> <img src="./Assets/Christ_the_redeemer.jpg" alt="Image not available"> </div>
        <div class="circle active borderr"> <img src="./Assets/colosseum.jpg" alt="Image not available"> </div>
        <div class="circle active borderr"> <img src="./Assets/Great_wall_of_China.jpg" alt="Image not available"> </div>
        <div class="circle active borderr"> <img src="./Assets/MachiPicchu.jpg" alt="Image not available"> </div>
        <div class="circle active borderr"> <img src="./Assets/TajMahal.jpg" alt="Image not available"> </div> -->
        <div class="circle active">1</div>
        <div class="circle active">2</div>
        <div class="circle active">3</div>
        <div class="circle active">4</div>
        <div class="circle active">5</div>
      </div>

      <button class="btn" id="prev" disabled>Prev</button>
      <button class="btn" id="next">Next</button>
    </div>
    <script src="script.js"></script>
  </body>
</html>

style.css - 

@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');

:root {
  --line-border-fill#3498db;
  --line-border-empty#e0e0e0;
}

* {
  box-sizingborder-box;
}

body {
  background-color#f6f7fb;
  font-family'Muli'sans-serif;
  displayflex;
  align-itemscenter;
  justify-contentcenter;
  height100vh;
  overflowhidden;
  margin0;
}

.container {
  text-aligncenter;
}

.progress-container {
  displayflex;
  justify-contentspace-between;
  positionrelative;
  margin-bottom30px;
  max-width100%;
  width350px;
}

.progress-container::before {
  content'';
  background-color: var(--line-border-empty);
  positionabsolute;
  top50%;
  left0;
  transform: translateY(-50%);
  height4px;
  width100%;
  z-index-1;
}

.progress {
  background-color: var(--line-border-fill);
  positionabsolute;
  top50%;
  left0;
  transform: translateY(-50%);
  height4px;
  width0%;
  z-index-1;
  transition0.4s ease;
}

.circle {
  background-color#fff;
  color#999;
  border-radius50%;
  height30px;
  width30px;
  displayflex;
  align-itemscenter;
  justify-contentcenter;
  border3px solid var(--line-border-empty);
  transition0.4s ease;
}

.circle.active {
  border-color: var(--line-border-fill);
}

.btn {
  background-color: var(--line-border-fill);
  color#fff;
  border0;
  border-radius6px;
  cursorpointer;
  font-familyinherit;
  padding8px 30px;
  margin5px;
  font-size14px;
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus {
  outline0;
}

.btn:disabled {
  background-color: var(--line-border-empty);
  cursornot-allowed;
}

img{
  height100px;
  width100px;
  border-radius50px;
}

.borderr{
  height120px;
  width120px;
  border-spacing15px;
}

script.js -
const progress = document.getElementById('progress')
const prev = document.getElementById('prev')
const next = document.getElementById('next')
const circles = document.querySelectorAll('.circle')

let currentActive = 1

next.addEventListener('click', () => {
    currentActive++

    if(currentActive > circles.length) {
        currentActive = circles.length
    }

    update()
})

prev.addEventListener('click', () => {
    currentActive--

    if(currentActive < 1) {
        currentActive = 1
    }

    update()
})

function update() {
    circles.forEach((circle, idx) => {
        if(idx < currentActive) {
            circle.classList.add('active')
        } else {
            circle.classList.remove('active')
        }
    })

    const actives = document.querySelectorAll('.active')

    progress.style.width = (actives.length - 1) / (circles.length - 1) * 100 + '%'

    if(currentActive === 1) {
        prev.disabled = true
    } else if(currentActive === circles.length) {
        next.disabled = true
    } else {
        prev.disabled = false
        next.disabled = false
    }
}

Output :-


Images for Reference:
     If you want to use images and want to get images, you can get from my previous blog-
https://bondasanathkumar.blogspot.com/2021/06/project-1-displaying-cards.html

Comments

Post a Comment

If you any doubts or Modifications I have to do, let me know.

Popular posts from this blog

Project 3 - Customized Rotating Navigation

Project 5 - Customized Scroll Animation