javascript - 如何制作一个带有两个彼此为 "push"的句柄的 jquery ui slider ?

标签 javascript jquery jquery-ui jquery-ui-slider

我想使用 jquery ui 制作一个带有两个 handle 的 slider ,以保持它们之间的最小空间。如果左 handle 试图与右 handle 交叉,则应插入右 handle 。反之亦然。这是一个示例(不要介意重叠,这并不重要):

http://jsfiddle.net/SP5VQ/

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

最佳答案

这有效。我从 $.ui.slider.prototype._slide 复制了代码,并删除了检查左 handle 是否大于右 handle 的部分。现在运行良好。

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 );
              }
            }
          }
        }

关于javascript - 如何制作一个带有两个彼此为 "push"的句柄的 jquery ui slider ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11585046/

相关文章:

javascript - Mapbox GL - 添加具有特定 id 的标记

javascript - Chart JS动态图表

jQuery - 将逗号包裹在 <span> 中?

c# - 通过身份验证时从 Web API Controller 操作返回图像

Jquery UI 工具提示不支持 html 内容

jquery-ui - JQuery .on() 仅使附加的所有其他元素可单击

javascript - Protractor :测试套件完成后清理

javascript - 将 mongodb bson.Objectid 从 JavaScript(前端)传递到 Go(后端)

javascript - 包含 jquery 破坏了我的简单网页

jquery - 如何通过 Jquery 对话框小部件使用缓动