我不知道这是否是去它的最好方法,但这种方法结束了为我工作。如果有人遇到同样的问题,我会在这里回答。
纵观jQuery API,看起来活动句柄是基于某种距离计算的,当我想要的只是被点击的句柄。
我覆盖了jQuery UI _mouseCapture事件并将其定制为点击敏感。它还需要一些硬集CSS类检测来确定哪个句柄是活动句柄。
通过做这样的事情,我能够避免修改任何库文件,只改变了少量的原始功能。
// Create the slider.
var slider = $('.slider').slider({//OPTIONS HERE});
// Get the slider and replace the _mouseCapture function with a custom one.
slider.data('ui-slider')._mouseCapture = function(event) {
var position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle,
that = this,
o = this.options;
if (o.disabled) {
return false;
}
this.elementSize = {
width: this.element.outerWidth(),
height: this.element.outerHeight()
};
this.elementOffset = this.element.offset();
// Get the element that the click was triggered on and set that to closestHandle. There was a bunch of distance calculation here previously - that has been removed.
currentHandle = $(event.toElement);
closestHandle = currentHandle;
// 'custom-handle-1' is a custom class I give to the left slider handle
// I know that my sliders will only have 2 values (so index will either be 0 or 1 always).
if (closestHandle.hasClass('custom-handle-1')) {
index = 0;
}
else {
index = 1;
}
allowed = this._start(event, index);
if (allowed === false) {
return false;
}
this._mouseSliding = true;
this._handleIndex = index;
this._addClass(closestHandle, null, "ui-state-active");
closestHandle.trigger("focus");
offset = closestHandle.offset();
mouseOverHandle = !$(event.target).parents().addBack().is(".ui-slider-handle");
this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
left: event.pageX - offset.left - (closestHandle.width()/2),
top: event.pageY - offset.top -
(closestHandle.height()/2) -
(parseInt(closestHandle.css("borderTopWidth"), 10) || 0) -
(parseInt(closestHandle.css("borderBottomWidth"), 10) || 0) +
(parseInt(closestHandle.css("marginTop"), 10) || 0)
};
if (!this.handles.hasClass("ui-state-hover")) {
this._slide(event, index, normValue);
}
this._animateOff = true;
return true;
};
缺点是,这可能与jQuery的用户界面的未来版本兼容,但是这是一个未来的问题(目前,这是1.12.1)。
实际的问题是'min'&'max'值,底部处理程序无法移动的原因是因为逻辑**最大值不能小于最小值** –
最小值和最大值是设置滑块本身的范围 - 可以选择高或低的手柄。我删除了这些值,问题依然存在。 –
选中此[小提琴](https://jsfiddle.net/rqpndLsL/3/) –