Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

538
Visualizações
How can I have a range slider with negative values?

I'm working with slider <input type="range" /> with:

  • minimum value: -20
  • maximum value: -90
  • step : 15
  • the value should be: -20, -35, -50, -65, -80
  • the value of -90 will never reached because of the step constraint.

It works with positive value (min: 20, max: 90, step: 15) but I don't have an idea dealing with negative value.
Can you help me?

Screenshot

Codesandbox.io link

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Set min value to -80 and add padding-left to the slider to let the user think that -90 is the min value.

const sliders = document.querySelectorAll("input[type=range]");

for (const slider of sliders) {
  slider.addEventListener('change', (e) => {
    e.target.nextElementSibling.value = e.target.value;
  });

  slider.nextElementSibling.value = slider.value;
}
input {
  padding-left: 15px;
}
<input type="range" min="-80" max="-20" step="15" />
<output></output>

about 4 years ago · Juan Pablo Isaza Relatório

0

You cannot do it by simply using HTML as -90 is lower than -20 so you cannot set min="-20" max="-80". But by using this trick you may achieve your output.

Keep the HTML as:

<input type="range" min="20" max="90" step="15"/>
<output></output>

Change your JavaScript to:

for (const slider of sliders) {
  slider.addEventListener("change", (e) => {
    e.target.nextElementSibling.value = "-" + e.target.value;
  });

  slider.nextElementSibling.value = "-" + slider.value;
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda