JSFiddle - React, Tailwind, and code Playground

by Tan

HTML

<div class="parent">
  <div class="divFill"><span></span></div>
  <div class="divLowerFill"><span></span></div>
  <input type="range" id="rangeinput">
  </div>
  
  
  <div id="test">
  
  </div>
  
    <div id="test2">
  
  </div>
  
      <div id="test3">
  
  </div>

CSS

body {margin:50px;}

/*********** Baseline, reset styles ***********/
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  width: 30rem;
  border:none;padding:0;margin:0;box-sizing: border-box;height: 2.5rem;

}

/* Removes default focus */
input[type="range"]:focus {
  outline: none;
  border:none;
}

/******** Chrome, Safari, Opera and Edge Chromium styles ********/
/* slider track */
input[type="range"]::-webkit-slider-runnable-track {
  background-color: #add8e6;
  border-radius: 0rem;
  height: 2.5rem;
  border:none;
}

/* slider thumb */
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; /* Override default look */
  appearance: none;
  margin-top: 0px; /* Centers thumb on the track */
  background-color: #808080;
  border-radius: 0rem;
  height: 2.5rem;
  width: 40px;
  border:none;

}



/*********** Firefox styles ***********/
/* slider track */
input[type="range"]::-moz-range-track {
  background-color: #add8e6;
  border-radius: 0rem;
  height: 2.5rem;
}

/* slider thumb */
input[type="range"]::-moz-range-thumb {
  background-color: #808080;
  border: none; /*Removes extra border that FF applies*/
  border-radius: 0rem;
  height: 2.5rem;
  width: 40px;

}




.parent {height:2.5rem;border:none;padding:0;
  display:inline-block;
  position:relative;
}

/* repplicating input range track background */
.divFill {
  position: absolute;right:0;top: 0;bottom:0;
  width: calc(50% - 20px);
  height: 100%;
   overflow:hidden;

}

/* track fill */
.divLowerFill {
  position: absolute;left:0;top: 0;bottom:0;
  height: 100%;
  width: calc(50% - 20px);
  pointer-events:none;
overflow:hidden;

}
.divFill span {position:absolute;left:0;top:0;display:block;width:30rem;height:100%;background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 25%);}
.divLowerFill span {position:absolute;right:0;top:0;display:block;width:30rem;height:100%;background: linear-gradient(90deg,...

JavaScript

var thumb = 40;
document.getElementById("rangeinput").addEventListener("input", function(e){
var rangeInput=document.getElementsByClassName("divLowerFill")[0];
var rangeInput2=document.getElementsByClassName("divFill")[0];

rangeInput.style.width=(e.target.offsetWidth-thumb)*e.target.value/100 +"px";
rangeInput2.style.width=(e.target.offsetWidth-thumb)-(e.target.offsetWidth-thumb)*e.target.value/100 +"px";

var test = document.getElementById("test");
test.innerHTML = e.target.offsetWidth*e.target.value/100;

var test2 = document.getElementById("test2");
test2.innerHTML = e.target.offsetWidth-e.target.value/100;

var test3 = document.getElementById("test3");
test3.innerHTML = e.target.offsetWidth-e.target.offsetWidth*e.target.value/100;
});