I have a simple slider divided into 24 steps (0-23), each representing an hour of the day. My objective is to animate the slider once so that every second, the value of the input and the slider increases by one - starting from 0 to 23 and then stopping (a total of 24 seconds). And then stop (loop ends).
.map-overlay input {
background-color: transparent;
display: inline-block;
width: 100%;
position: relative;
margin: 0;
cursor: ew-resize;
}
<div class='map-overlay-inner'>
<h2>Passengers by hour</h2>
<label id='variable'></label>
<input id='slider' type='range' min='0' max='23' step='1' value='0' />
</div>
var variables = [ '0', '1', '2', '3', '4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23',
];
function filterBy(variable) {
var filters = ['==', 'variable', variable];
map.setFilter('circles', filters);
map.setFilter('labels', filters);
// Set the label to the hour
document.getElementById('variable').textContent = variables[variable];
}
document.getElementById('slider').addEventListener('input', function(e) {
var variable = e.target.value
filterBy(variable);
});
At this point, the value changes on manual input with e.target.value
When I implement this solution to move the slider by one, however, the textContent does not change and for some reason the slider jumps from 1 to 11. Why does this happen and can anyone recommend a solution?
var myVar = setInterval(myTimer, 1000);
function myTimer() {
document.getElementById("slider").value += 1;
}