我已经实现了jQuery range slider在我正在构建的网页上,但似乎无法使其捕捉到特定的非均匀分布值。有谁知道 jQuery slider 是否可以实现这一点,或者是否有我可以使用的替代方案?
举一个更具体的例子,假设我的范围是 0 到 100,并且我有一个像 [0, 7, 32, 61, 67, 90, 100]
这样的数组。我希望范围 slider 只能选择数组中的值。
最佳答案
您可以使用slide
callback限制允许的位置:
Triggered on every mouse move during slide. The value provided in the event as
ui.value
represents the value that the handle will have as a result of the current movement. Canceling the event will prevent the handle from moving and the handle will continue to have its previous value.
所以你只需要这样的东西:
var allowed = { 0: true, 7: true, /*...*/ 100: true };
$("#slider").slider({
//...
slide: function(event, ui) {
if(!allowed[ui.value])
return false;
}
});
当allowed.indexOf(ui.value)
为负数时,您还可以使用allowed
数组并return false
;我认为使用对象读起来更好。
关于jquery - 具有任意捕捉点的范围 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8729009/