Framer Classic » Slider component » Knob position vs. slider value

Knob position vs. slider value

With the pointForValue() function you can get a readout of what would be the knob’s position for a particular value.

And valueForPoint() works the other way round: you give it a (hypothetical) position of the knob, and it will return the value this would generate.

These functions don’t change anything to the slider itself; they just return the numbers the slider uses internally.

We have a default slider:

slider = new SliderComponent

With its default width of 300, default min value of 0, and default max of 1, the position for value 0.5 will be at 150 points.

# What would be the location of the knob
# for a value of 0.5?
print slider.pointForValue 0.5

» 150

This, of course, is what would be the x position of the knob inside its parent (the slider itself) and not the position of the knob on the screen. (For a vertical slider you will get a y value.)

And the valueForPoint() function does exactly the reverse.

# What would be the slider’s value with
# the knob halfway (at 150 points)?
print slider.valueForPoint 150

» 0.5
Open in Framer

Leave a Reply