Я написал код для индикатора выполнения, который будет динамически увеличиваться при нажатии на конкретную веху.
Когда я нажимаю на веху, я хочу, чтобы цвет оставался красным, но не могу добавить onclick
метод для каждого деления.
Я обновил код, я вставил столбцы в строку, так что я хочу сохранить индикатор выполнения в первом столбце, но точки переполнены.Может ли кто-нибудь помочь?
var mileStones = Array.from(document.querySelectorAll('.primary-color'));
mileStones.forEach(elem => {
elem.onclick = function() {
const current = this;
let flag = false;
document.getElementById('pp').style.width = current.dataset.width + '%';
mileStones.forEach(elem => {
elem.classList.add('active');
if (flag) elem.classList.remove('active');
if (current.id === elem.id) flag = true;
});
}
});
.progress {
width: 100%;
height: 6px;
margin-top: 50px;
}
.progress-bar {
width: 50%;
background-color: #00A2DB;
}
#one,
#two,
#three,
#four,
#five {
position: absolute;
margin-top: -8px;
z-index: 1;
height: 20px;
width: 20px;
border-radius: 25px;
}
#one,
.percent {
left: 0%;
}
#two,
.percent1 {
left: 25%;
}
#three,
.percent2 {
left: 50%;
}
#four,
.percent3 {
left: 75%;
}
#five,
.percent4 {
left: 100%;
}
.primary-color {
background-color: pink;
}
.primary-color:active {
background-color: red;
}
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
</head>
<div class="row">
<div class="col-9">
<p>Bussiness case completion:</p>
<div class="progress" id="progress">
<div class="primary-color" id="one" data-width="0"></div>
<div class="primary-color" id="two" data-width="25"></div>
<div class="primary-color" id="three" data-width="50"></div>
<div class="primary-color" id="four" data-width="75"></div>
<div class="primary-color" id="five" data-width="100"></div>
<div class="progress-bar" id="pp" role="progressbar" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" onclick="progressBarTest()"></div>
</div>
</div>
<div class="col-3 align-self-end">
<p class="primary1"> ID 453</p>
</div>
</div>