У вас может быть много цветов, чем вы можете хранить данные в массиве в js. Если у вас очень ограниченная комбинация, вы можете создать класс как .progress-done.success
.progress-done.error
.progress-done.info
Пример:
const progresses = document.querySelectorAll(".progress-done");
const colors = [
["#f83600", "#f9d423"],
["#f8ff00", "#f9d423"],
["#f83660", "#f9d423"],
["#f86600", "#f9d423"],
["#f86600", "#f9d423"],
["#f86600", "#f9d423"]
];
progresses.forEach((progress, index) => {
const [bgColor, bgShadow] = colors[index];
const background = `linear-gradient(to right, ${bgColor} 0%, ${bgShadow} 100%)`;
const boxShadow = `0 3px 3px -5px ${bgColor}, 0 2px 5px ${bgShadow}`;
const done = progress.getAttribute('data-done');
const duration = getComputedStyle(progress).transitionDuration;
const timeoutDuration = +duration.slice(0, 1) * 1000;
progress.style.width = done + "%";
progress.style.opacity = 1;
progress.style.background = background;
progress.style.boxShadow = boxShadow;
for (let i = 0; i <= done; i++) {
setTimeout(() => {
progress.innerText = i + "%";
}, (timeoutDuration / done) * i);
}
});
// By class name
progresses[4].className += " success"
progresses[5].className += " info"
.progressbar h3 {
font-family: 'Poppins', sans-serif;
font-size: 1.2em;
color: #666666;
margin: auto;
}
.skill-progress {
margin-bottom: 10px;
}
.progress {
background-color: #f2f2f2;
border-radius: 20px;
height: 25px;
width: 450px;
margin: 20px auto;
}
.progress-done {
background: linear-gradient(to right, #f83600 0%, #f9d423 100%);
box-shadow: 0 3px 3px -5px #f83600, 0 2px 5px #f9d423;
border-radius: 20px;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 0;
opacity: 0;
transition: 4s ease 0.3s;
}
.progress-done.success {
background: linear-gradient(to right, #00ff00 0%, #f9d423 100%) !important;
box-shadow: 0 3px 3px -5px #00ff00, 0 2px 5px #f9d423!important;
}
.progress-done.info {
background: linear-gradient(to right, #00ffff 0%, #00ff00 100%)!important;
box-shadow: 0 3px 3px -5px #00ffff, 0 2px 5px #00ff00!important;
}
<div class="progressbar">
<h1 class="title">My Tools & Skills</h1>
<div class="skill-progress">
<h3>HTML5</h3>
<div class="progress">
<div class="progress-done" data-done="70">
</div>
</div>
<div class="progress">
<div class="progress-done" data-done="60">
</div>
</div>
<div class="progress">
<div class="progress-done" data-done="50">
</div>
</div>
<div class="progress">
<div class="progress-done" data-done="40">
</div>
</div>
</div>
</div>