javascriptjqueryjquery-uisliderjquery-ui-slider

Jquery Slider UI dynamic step size


I have a slider with the following properties:

My goal is to force the user to choose between only 7 points (for example: "2, 3, 4, 26, 39, 52, 65") and nothing more.

How do I create a dynamic step size or how do I allow only those points to be the slider steps?


Solution

  • I suggest that you look at the slide event. Doc is here. It says

    Return false in order to prevent a slide, based on ui.value.

    So you'll just have to return false when the value is not the one you're aiming.

    Edit: Damn it, the link just got you to the slider page. What I'm talking about is in the Events tab, and it's the one named slide

    Edit2: a fiddle using it. The main difference with the other solution is that the sliding won't be uniform in this one.

    Edit3: Another fiddle. In this one , if an incorrect value is reached at the end of the slide, it will go back to the previous correct value.