Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
How to autoplay a slider range with javascript

Could you please help me?

I have a map that change every 15 minutes with a slider range. I would like to play all range here (from 06:00 to 12:00 with a step of 15 mn) when users click on the play button.

    <div class="#" id="map"></div>
    <div id='console'>
        <div class='session' id='sliderbar'>
          <h2>Time: <label id='active-hour'>6H</label></h2>
          <input id='slider' class='row' type='range' min='0' max='24' step='1' value='0' />
          <button type="button" class="btn btn-success" id="btnPlay" onclick="Play()">Play</button>
        </div>           
    </div>

I creat the below function for the onclick even in the player button. But it doesn't work as expected.

function Play() {
  var first_color = hex2rgb(document.getElementById("first").value)
  var second_color = hex2rgb(document.getElementById("second").value)
  
    for (let i = 0; i <25; i++) {
      document.getElementById('slider').addEventListener('input', (event) => {
        //const hour = parseInt(event.target.value)
        map.setPaintProperty('lines', 'fill-color', [
          'interpolate', ['linear'],
          ['at', i, ['get', 'speed_output']],
          30, first_color,
          70, second_color,
        ]);
        document.getElementById('active-hour').innerText = time[i]
      });
    }
}

The output with the slider range enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda