Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Make step on slider or scroll bar element as HTML input range element

Community Beginner ,
Apr 24, 2023 Apr 24, 2023

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.

TOPICS
Actions and scripting
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Apr 24, 2023 Apr 24, 2023

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();

 

 

 
 

 

 

Translate
Adobe
Guide ,
Apr 24, 2023 Apr 24, 2023

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();

 

 

 
 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 24, 2023 Apr 24, 2023

Thank you. Very elegant solution. And how simple.))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 24, 2023 Apr 24, 2023

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.

 

: )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 24, 2023 Apr 24, 2023

Клавиатуру можно через .addEventListener('keyup', h) (например) поймать. А вот то, что сегодня у меня с математикой не лады - это точно 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 24, 2023 Apr 24, 2023
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines