啊,我喜欢吃完 11k 个库,你不是吗?:)
注意:以下是 jQuery UI 1.8.5
无论如何,这是一个非常干净的解决方案:
// add some stuff to the slider instance
this._handleIndex = null;
this._handleStartValue = -1;
// remember the starting values in _mouseCapture
this._handleStartValue = this.values( this._handleIndex );
this._mouseDownOffset = this._normValueFromMouse( { x: event.pageX, y: event.pageY } );
// modify _mouseDrag
oldValue = this.values( this._handleIndex ),
curValue;
curValue = this.values(this._handleIndex);
if ( curValue === oldValue && this._handleStartValue !== -1 ) {
if ( normValue - this._mouseDownOffset > 0
&& ( curValue === this.values( ( this._handleIndex + 1 ) % 2 ) )
&& oldValue === this._handleStartValue) {
this._handleIndex = (this._handleIndex + 1) % 2;
}
} else {
this._handleStartValue = - 1
}
// reset everything in _mouseStop
this._handleIndex = null;
this._handleStartValue = -1;
这就是它的全部内容,哦,它是如何工作的,当然:
- 保存起始鼠标偏移量以及初始选择句柄的值
- 拖动时将旧值与活动手柄的当前值进行比较,并检查起始位置是否有效
- 如果没有区别,我们检查是否可以进一步拖动活动手柄是否会有区别
- 如果是这种情况,我们检查两个句柄是否具有相同的值,这意味着它们在彼此之上
- 现在我们检查当前选择的手柄是否还没有被拖动
- 最后,如果这一切都是真的,我们切换手柄
- 如果用户现在更改了值,我们会使我们的起始位置无效,以便手柄之间不再有切换
为了您的高兴,这里有一个diff
:
9960c9960,9962
<
---
>
> this._handleIndex = null;
> this._handleStartValue = -1;
10215a10218,10219
> this._handleStartValue = this.values( this._handleIndex );
> this._mouseDownOffset = this._normValueFromMouse( { x: event.pageX, y: event.pageY } );
10243c10247,10249
< normValue = this._normValueFromMouse( position );
---
> normValue = this._normValueFromMouse( position ),
> oldValue = this.values( this._handleIndex ),
> curValue;
10246c10252,10263
<
---
> curValue = this.values(this._handleIndex);
> if ( curValue === oldValue && this._handleStartValue !== -1 ) {
> if ( normValue - this._mouseDownOffset > 0
> && ( curValue === this.values( ( this._handleIndex + 1 ) % 2 ) )
> && oldValue === this._handleStartValue) {
>
> this._handleIndex = (this._handleIndex + 1) % 2;
> }
>
> } else {
> this._handleStartValue = - 1
> }
10257a10275,10276
> this._handleStartValue = -1;
> this._handleIndex = null;
保存它ui.diff
然后做patch -i ui.diff jquery-ui.js
。