具有多个手柄的 JQuery UI 滑块:如何阻止手柄交叉?
我正在开发一个快速解决方案,它使用具有多个手柄的滑块来定义动态布局的宽度。
我尝试使用 ExtJS3 和最新的 JQuery UI。
在 ExtJS 中,您可以约束句柄,这样它们就不会相互交叉,这是一种实现我需要的 UI 的非常直观的方法,但是有一些原因我宁愿不将 ExtJS 用于海洋中的一个“岛屿” jQuery。
那么,有谁知道一个秘密属性,或者一些限制 JQuery 滑块中多个句柄的代码?
为了清楚起见:如果您有一个带有 2 个手柄的滑块,一个位于 40,一个位于 60;该约束将阻止您将 60 处的手柄拖动到 20 处,而无需先移动 40 处的手柄。
I'm developing a quick solution that uses a Slider with multiple handles to define widths for a dynamic layout.
I've attempted to use both ExtJS3 and the latest JQuery UI.
In ExtJS, you can constrain the handles so the don't cross over each other, and it's quite an intuitive approach to the UI I need, however there are reasons why I would rather not use ExtJS for one 'island' in a sea of JQuery.
So, does anyone know of a secret attribute, or a bit of code that constrains multiple handles in the JQuery slider ?
For clarity: if you have a slider with 2 handles, one at 40 and one at 60; the constraint would stop you dragging the handle at 60 down to 20, without first moving the 40 one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在滑动事件中,您可以通过检查滑块值并返回 true 以允许滑动或返回 false 以阻止滑动来限制手柄移动(有关更多信息,请参阅 jQuery UI 文档)
In the slide event you can constrain the handle movement by checking the slider values and returning true to allow the slide or false to prevent it (see the jQuery UI docs for more information)
Jquery 滑块使用什么代码?查看范围滑块演示,它有两个手柄,并且不可能交叉它们。
What code are you using for the Jquery slider? Looking at the range slider demo, it has two handles and its not possible to cross them.
正如 @madcapnmckay 指出的,如果您有一个带有两个手柄的滑块,并且选项中的
range: true
,则手柄不能相互拖动。我遇到了一个问题,它没有正确约束,但事实证明我有一个字符串
'true'
而不是布尔值true
As @madcapnmckay pointed out, if you have a slider with two handles and the
range: true
in the options the handles cannot be dragged past each other.I was having a problem where it wasn't constraining properly but it turned out I had a string
'true'
instead of a booleantrue
我来晚了一点,但我想分享我最紧凑但可读的方法来做到这一点。从技术上讲,它与@tototresde 的答案非常相似。
I'm a bit late to the party here, but I wanted to share my most compact-yet-readable way to do this. Technically it's pretty similar to @tototresde's answer.
检查这个解决方案:
Check this solution: