Max : 100
Max : 200
Max : 300
Max : 400
@import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap");
body{
font-family: 'Roboto', sans-serif;
}
.progress-wrap {
display: flex;
column-gap: 30px;
}
.progress-input {
width: 15px;
height: 200px;
background: #ededed;
border-radius: 20px;
margin: auto;
margin-bottom: 10px;
position: relative;
box-shadow: 1px 1px 2px rgb(0 0 0 / 10%);
}
.progress-line {
height: 50px;
position: absolute;
background: red;
width: 15px;
bottom: 0px;
border-radius: 20px;
transition: 0.7s ease;
height:100%;
}
.progress-line::before {
content: '';
display: block;
width: 20px;
height: 20px;
background: #FFF;
border-radius: 20px;
position: absolute;
top: -1px;
left: 0px;
transform: translateX(-3px);
box-shadow: 0px 2px 5px rgba(0,0,0,0.2);
}
.progress-num {
padding: 8px 5px;
border-radius: 10px;
border: 1px solid #ddd;
text-align: center;
font-size: 16px;
}
.progress-item .max {
text-align: center;
margin: 0 0 6px 0;
font-weight: 600;
font-size: 14px;
}
.progress-num::-webkit-outer-spin-button,
.progress-num::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
.progress-num[type=number] {
-moz-appearance: textfield;
}
const prg_num = document.querySelectorAll('.progress-num');
const getHeight = (max, value) => {
max = Number(max)
value = Number(value)
if(value <= max){
return (value / max) * 100
}else{
return 100
}
}
prg_num.forEach((ele) => {
let defaultValue = Number(ele.value)
let maxValue = Number(ele.getAttribute("max"))
let minValue = Number(ele.getAttribute("min"))
let prg_num_id = ele.getAttribute('progress-id');
//Set Default Value
let barHeight = getHeight(maxValue, defaultValue)
setTimeout(function(){
document.getElementById(prg_num_id).querySelector('.progress-line').style.height = barHeight+"%";
},1000)
//Change Value on Keyup
ele.addEventListener('keyup', function(){
let newValue = Number(ele.value)
if(newValue >= maxValue) {
ele.value = maxValue
}
if(newValue <= minValue) {
ele.value = minValue
}
let ele_max_height = Number(ele.getAttribute('max'));
let new_height = getHeight(ele_max_height, newValue)+"%";
document.getElementById(prg_num_id).querySelector('.progress-line').style.height = new_height;
});
});