Copy link to clipboard
Copied
In HTML5 there is an input type="range" element with which you can set the slider's movement step to the desired number:
<input type="range" min="0" max="70" step="0.05" >
In the example above, the step is 0.05 and it is not possible to select a number on the slider that is not a multiple of 0.05.
Is it possible to do something similar in the Window('dialog') object?
I tried stepdelta and jumpdelta of the Scrollbar object, but there is a difficulty.
If I move the slider to, for example, 2.35 with steps set to 1 unit, when I apply the step the slider will set to either 3.35 or 1.35 depending on the direction.
It is necessary that the slider's movement be clear only on the numbers that are specified in the step property.
For example, if the step is 0.5, the slider can only take values equal to half a unit.
1 Correct answer
With each change in the position of the slider, we can adjust its value by the amount we need:
var step = 0.5;
var w = new Window("dialog"),
st = w.add("statictext {text:'00000'}"),
sl = w.add("slider {minvalue:0, maxvalue:70, value:0, preferredSize:[200,-1]}");
sl.onChanging = function (){st.text = this.value = Math.round(this.value/step)*step;}
w.onShow = function (){st.text = sl.value}
w.show();
Explore related tutorials & articles
Copy link to clipboard
Copied
With each change in the position of the slider, we can adjust its value by the amount we need:
var step = 0.5;
var w = new Window("dialog"),
st = w.add("statictext {text:'00000'}"),
sl = w.add("slider {minvalue:0, maxvalue:70, value:0, preferredSize:[200,-1]}");
sl.onChanging = function (){st.text = this.value = Math.round(this.value/step)*step;}
w.onShow = function (){st.text = sl.value}
w.show();
Copy link to clipboard
Copied
Thank you. Very elegant solution. And how simple.))
Copy link to clipboard
Copied
The way is so-so. Try to check how in this example it works with step = 20. In addition, using the keyboard to move the slider does not work, or it is buggy all the time even with other steps.
: )
Copy link to clipboard
Copied
Клавиатуру можно через .addEventListener('keyup', h) (например) поймать. А вот то, что сегодня у меня с математикой не лады - это точно 🙂
Copy link to clipboard
Copied
Yes. I've already tried putting a step of 50. And yes. it's interesting to jump)))
But as an option...
I have a small pitch relative to the range so that will do.

