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

118
Visualizações
Range slider - avoid moving forward when reaching a value specified in another element

lets say i have a range slider going from value 1 to 100 by default i would be able to slide it going from 1 to 100.

I would like the slider to block, when reaching a value specified in another element. I've been trying it like this (where 20 would be the value in the element, just easier for the example), but that isn't perfect. the Thumb does indeed stop, but i think internally if you keep sliding, it will remember that value, even if you don't see it.

EDIT: would a for loop be something good here?

for(i=slider.value;i<20;i++)
...
if (slider.value >=20)
slider.value=20

Anyone better at this who can help?

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

0

Wrap everything in a <form> if you haven't already then assuming your limit is set by another <input>, assign an event handler to the <form> so it will trigger whenever there's an "input" event. Have the event handler change the [max] attribute value of the range input to the [value] of the limit <input>.

const limit = e => {
  const io = e.currentTarget.elements;
  let max = io.limit.value;
  io.range.max = max;
  io.view.value = io.range.value;
};

const ui = document.forms.ui;
ui.oninput = limit;
input {
  display: inline-block;
  width: 5ch;
  text-align: right;
}

#range {
  width: 20ch
}
<form id='ui'>
  <input id='limit' type='number' max='100' value='100'>
  <output id='view'>0</output><br>
  <input id='range' type='range' min='0' max='100' value='0'>
</form>

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