p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

Slider step

Open ynaoto opened this issue 12 years ago • 3 comments

Hi, A quick question. How can I set step value for the slider less that 1 for example 0.2?

ynaoto avatar Aug 09 '14 14:08 ynaoto

I don't believe createSlider() has those arguments (http://p5js.org/reference/#p5/createSlider). You can work around this by doing some math. For example you want to count by 0.2 from 0 to 10. Create a slider that has values from 0 to 50 and then just divide slider.value() by 5.

KevinGutowski avatar Aug 11 '14 19:08 KevinGutowski

@ynaoto there is no specific method in p5, but you can use .elt to access the underlying html element, and then call any of the methods on that. http://www.w3schools.com/jsref/dom_obj_range.asp

so this would work:

function setup() {
  s = createSlider(0, 50);
  s.elt.step = 5;
}

lmccart avatar Aug 11 '14 19:08 lmccart

I got it, thanks!

ynaoto avatar Aug 12 '14 13:08 ynaoto