Coder Wrap provides free to use snippets Coder Wrap provides free to use snippets

Back to Others
Preview Source Code
Download
HTML
CSS
/**Typeo CSS Start (Note if is not need so remove)**/
@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap");
* {
  box-sizing: border-box;
}

body {
  font-family: "Poppins", sans-serif;
  color: #000;
  box-sizing: border-box;
  background-color: #f5f5f5;
}
.cw-container {
    max-width: 500px !important;
    width: 100%;
    margin: auto; 
    justify-content: center;
    display: flex;
    flex-flow: row wrap;
    align-items: center;
}
/**Typeo CSS End (Note if is not need so remove)**/

.cw-progress-container{
    width: 100%;
    height: 200px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative; 
}
.cw-progress-bar{
    background-color: white;
    border: 3px solid #e0e0e0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 2;
    transition: .4s ease;
}
.cw-progress-bar.cw-active{
   border-color:#3498db;
}

.cw-progress-container::before{
    content: '';
    width: 100%;
    height: 5px;
    background: #e0e0e0;
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.cw-progress-line{
    background-color:#3498db;
    position: absolute;  
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 4.5px;
    width:  0%;
    z-index: 1;
    transition: .4s ease;
}

.cw-btn {
    background-color:#3498db !important;
    color: white !important;
    border: 0 !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    font-family: inherit !important;
    padding: 8px 30px !important;
    margin: 5px !important;
    font-size: 14px !important;
    margin: 0 25px 0 25px !important;
}

.cw-btn:active{
    outline: scale(.98) !important;
}
.cw-btn:focus{
    outline: none !important;
}

.cw-btn:disabled{
    background-color: #e0e0e0 !important;
    cursor: not-allowed !important;
    color: #000 !important;
}
JS
const nextButton = document.getElementById('next')
const prevButton = document.getElementById('prev')
const progLine = document.getElementById('progress')
const progBars = document.querySelectorAll('.cw-progress-bar')
let currentActive = 1;
nextButton.addEventListener('click', () => {
    currentActive++
    if(currentActive > progBars.length){
        currentActive = progBars.length;
    }
    update()
})
prevButton.addEventListener('click', () => {
    currentActive--
    if(currentActive < 1){
        currentActive = 1;
    }
    update()
})
function update() {
    progBars.forEach((bar, index) => {
        if(index < currentActive){
            bar.classList.add('cw-active')
        }
        else{
            bar.classList.remove('cw-active')
        }
    })

    const actives = document.querySelectorAll('.cw-active')
    
    progLine.style.width = (actives.length -1)/ (progBars.length - 1) * 100 + '%'

    if(currentActive === 1){
        prevButton.disabled = true
    }
    else if (currentActive === progBars.length){
        nextButton.disabled = true
    }
    else{
        prevButton.disabled = false
        nextButton.disabled = false
    }
}

Related Snippets

Leave a comment

Your email address will not be published. Required fields are marked *