我不知道這是否是去它的最好方法,但這種方法結束了爲我工作。如果有人遇到同樣的問題,我會在這裏回答。
縱觀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/) –