2
$\begingroup$

I am trying to implement a slider whose control range varies depending on the current value:

{Dynamic@asd, 
Slider[Dynamic[asd], 
Dynamic @Which[asd < 10, {1, 10}, asd >= 10 , {9, 50, 1}]]}

However I now have the problem that the slider remains in place once the control scales change and thus the value "leaps" as soon as the scales change. To Illustrate: once i reach ten the scale changes but the slider remains in place and thus the value goes immediately to 50 (the "new" ten). Is it possible to have the slider jump instead of the value? Perhaps by briefly locking the value at ten?

$\endgroup$

2 Answers 2

2
$\begingroup$

I believe the jump in value of asd happens because you're dragging the indicator with the mouse when the range is reset. Here is a way that does what you want, I think. It interrupts the mouse-dragging by creating a new Slider when the boundary is reached.

{Dynamic@asd, 
 Dynamic@Slider[Dynamic[asd], 
   Which[asd < 10, {1, 10}, asd >= 10, {9, 50, 1}]]}

(Personally, I don't like the way it behaves, but I think it's what you're after. If you want the mouse action to continue, then the mouse position on the screen would need to be changed. As yet, I'm not sure this can be done.)

$\endgroup$
0
$\begingroup$

Maybe this is also an acceptable approach depending on your needs.

asd=1;
{Slider[Dynamic[asd, (asd = If[# <= 10, #, Round@#]) &], {1, 50}], Dynamic@asd}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.