help with jquery slider range option
Is there开发者_Python百科 a way to limit the slider options in jQuery UI slider?
I have a slider that is broken up into 5 parts.
However, I only want options 2,3, and 4 available. I don't want the handle to go to 1 or 5.
how do you restrict this?
Thanks!
You can listen to the slide event and test for it's position.
When it's at 1 or 5, you can return false
and cancel the event.
This seems to work
$( ".selector" ).slider({
min: 1,
max: 5,
value: 2,
slide: function(event, ui) {
if(ui.value == 1 || ui.value == 5)
return false;
}
});
Have a play here.
You can't directly change setting to do this if you want to keep 1 and 5 on the slider. If you only want 2,3 & 4 you can use:
$( ".selector" ).slider({ min: 2, max: 4 });
If you want to keep 1 and 5 you will need to write an onChange function. Similar to:
$( ".selector" ).slider({
change: function(event, ui) {
this.value == 1? this.value = 2: this.value; //
this.value == 5? this.value = 4: this.value;
}
});
Not sure if that is the right syntax, you will need to check.
精彩评论