Nick
Nick

Reputation: 14283

javascript - logaritmic scale in a slider

I've searched here and there are a few similar questions but none really suit my needs.

I need to change the default slider behavior so that it allows a scale to be between 1 and 24 (day) with these values as possible values:

1 2 3 4 5 6 9 12 18 24

I don't even know where to start with this. Any help would really be appreciated as I am not really good at math and I don't know what formula I can use to achieve this.

Thanks a lot

Upvotes: 0

Views: 118

Answers (1)

Kamil Kiełczewski
Kamil Kiełczewski

Reputation: 92427

Try

let values = [1, 2, 3, 4, 5, 6, 9, 12, 18, 24];

let change = (e) => {
  document.querySelector('div').innerText = 'day: '+values[e.target.value];
}
<input type="range" min="0" max="9" step="1" oninput="change(event)" value=0>
<div>day: 1</div>

Upvotes: 2

Related Questions