var slider = document.getElementById("slider"), color = document.getElementById("color");
color.oninput = function() {
slider.style.backgroundImage = "linear-gradient(to right,rgba(0,0,0,0),"+color.value+")";
let rgb = hexToRgb(color.value);
document.getElementById("test").style.backgroundColor = "rgba("+rgb.r+","+rgb.g+","+rgb.b+","+slider.value+")";
}
slider.oninput = function() {
let rgb = hexToRgb(color.value);
document.getElementById("test").style.backgroundColor = "rgba("+rgb.r+","+rgb.g+","+rgb.b+","+slider.value+")";
}
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background-image: linear-gradient(to right,rgba(0,0,0,0),#00ffff);
outline: none;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 10px;
height: 30px;
background: #4CAF50;
cursor: pointer;
}
<input type=color value=#00ffff id="color">
<input type="range" min="0" max="1" value="1" step="0.01" class="slider" id="slider">
<div id="test" style="width: 100px;height: 100px;"></div>