Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.)

share|improve this answer

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

asd=1;
{Slider[Dynamic[asd, (asd = If[# <= 10, #, Round@#]) &], {1, 50}], Dynamic@asd}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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