steevehook
8/22/2018 - 2:40 PM

Add value CSS variable for input

Add value CSS variable for input, in order to be able to be styled from CSS

input {
  appearance: none;
  background: linear-gradient(to right, #f06 calc(1% * var(--value)), white 0);
}
for (let input of document.querySelectorAll('input')) {
  input.style.setProperty('--value', input.value);
}

document.addEventListener('input', e => {
  input.style.setProperty('--value', e.target.value);
});