<div class="range-wrap range_container">
<input type="range" class="range questions__range" min="5" max="80" value="5">
<output class="bubble"></output>
</div>
.range {
appearance: none;
border-radius: 2px;
height: 5px;
width: 230px;
outline: 0;
background: #22243e;
border-radius: 5px;
}
.range::slider-thumb {
appearance: none;
width: 4px;
height: 16px;
background: #00d3ff;
border-radius: 18px;
cursor: pointer;
transition: 0.1s;
transition: 0.1s;
}
.range-wrap {
width: 230px;
position: relative;
}
.range-wrap__top {
display: box;
display: flexbox;
display: flex;
bottom: 50%;
position: absolute;
width: 230px;
box-pack: justify;
flex-pack: justify;
justify-content: space-between;
box-align: center;
flex-align: center;
align-items: center;
}
.range-wrap {
position: relative;
margin: 0;
margin-top: 15px;
margin-bottom: 15px;
}
.range {
width: 100%;
margin: 0;
}
.bubble {
background: url(https://svgshare.com/i/Mb9.svg) no-repeat center;
color: #00d3ff;
position: absolute;
border-radius: 4px;
width: 30px;
height: 26px;
font-size: 10px;
display: box;
display: flexbox;
display: flex;
box-align: center;
flex-align: center;
align-items: center;
box-pack: center;
flex-pack: center;
justify-content: center;
left: -13px;
padding-bottom: 9px;
top: -28px;
pointer-events: none;
}
body {
background: #131429;
}
.range-wrap {
margin-top: 30px;
margin-left: 30px;
}
const allRanges = document.querySelectorAll(".range-wrap");
const thumbWidth = 4;
const bubbleWidth = 30;
allRanges.forEach(wrap => {
const range = wrap.querySelector(".range");
const bubble = wrap.querySelector(".bubble");
range.addEventListener("input", () => {
setBubble(range, bubble);
});
setBubble(range, bubble);
});
function setBubble(range, bubble) {
let val = range.value;
const min = range.min ? range.min : 0;
const max = range.max ? range.max : 100;
const newVal = Number(((val - min) * 100) / (max - min));
bubble.innerHTML = val;
const leftOffset = bubbleWidth / 2 - thumbWidth * ((50 - newVal) / 100);
// Sorta magic numbers based on size of the native UI thumb
bubble.style.left = `calc(${newVal}% - ${leftOffset}px)`;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.