2

我想使用 jquery ui 制作一个带有两个句柄的滑块,它们之间保持最小的空间。如果左把手试图穿过右把手,则应推动右把手。反之亦然。这是一个示例(不要介意重叠,这并不重要):

http://jsfiddle.net/SP5VQ/

只要移动缓慢,它就可以工作,但如果鼠标移动得太快,它会在“推动”场景中失败。我认为从“滑块”事件中设置滑块值可能有问题。

4

1 回答 1

4

这行得通。我复制了代码$.ui.slider.prototype._slide并删除了检查左手柄是否大于右手柄的部分。现在效果很好。

http://jsfiddle.net/Nk8ap/

        $.ui.slider.prototype._slide = function ( event, index, newVal ) {
          var otherVal,
            newValues,
            allowed;

          if ( this.options.values && this.options.values.length ) {
            otherVal = this.values( index ? 0 : 1 );
            if ( newVal !== this.values( index ) ) {
              newValues = this.values();
              newValues[ index ] = newVal;
              // A slide can be canceled by returning false from the slide callback
              allowed = this._trigger( "slide", event, {
                handle: this.handles[ index ],
                value: newVal,
                values: newValues
              } );
              otherVal = this.values( index ? 0 : 1 );
              if ( allowed !== false ) {
                this.values( index, newVal, true );
              }
            }
          } else {
            if ( newVal !== this.value() ) {
              // A slide can be canceled by returning false from the slide callback
              allowed = this._trigger( "slide", event, {
                handle: this.handles[ index ],
                value: newVal
              } );
              if ( allowed !== false ) {
                this.value( newVal );
              }
            }
          }
        }
于 2012-07-20T20:02:33.330 回答