Yi *_*ang 8 javascript jquery jquery-ui jquery-ui-slider
我有这个简单的jQuery UI Slider设置,它有一个范围和两个重叠的默认值.在这个jsfiddle中可以找到整个东西(有一些铃声和口哨声):http://jsfiddle.net/yijiang/XeyGS/
$('#slider').slider({
min: 1,
max: 11,
range: true,
values: [4, 4]
});
Run Code Online (Sandbox Code Playgroud)
这样做的问题是,当您尝试向右拖动单个可见句柄时,它会失败,因为jQuery UI总是将最小句柄置于顶部.出于多种原因,这显然是不好的.
有没有办法允许jQuery UI根据用户开始拖动的方向选择要拖动的句柄?
啊,我喜欢吃11k libs,不是吗?:)
注意:以下内容适用于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;
Run Code Online (Sandbox Code Playgroud)
这就是它的全部,哦它是如何工作的,当然:
为了您的愉快,这里是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;
Run Code Online (Sandbox Code Playgroud)
保存它ui.diff然后做patch -i ui.diff jquery-ui.js.
我想说这是一个错误,尤其是因为当两个滑块手柄都位于最小/最左侧位置时,已经有逻辑阻止 \xe2\x80\x98deadlock\xe2\x80\x99 发生:
\n\n// workaround for bug #3736 (if both handles of a range are at 0,\n// the first is always used as the one with least distance,\n// and moving it is obviously prevented by preventing negative ranges)\nif( o.range === true && this.values(1) === o.min ) {\n index += 1;\n closestHandle = $( this.handles[index] );\n}\nRun Code Online (Sandbox Code Playgroud)\n\n工单 #3736似乎仍处于开放状态,其中提到了您遇到的具体问题。
\n| 归档时间: |
|
| 查看次数: |
3931 次 |
| 最近记录: |