jQuery UI Range Slider - 每个手柄的工具提示
我使用 jQuery Range 滑块让用户选择一天中的时间范围(即 10:00 - 18:00)。
目前一切正常,我的输出显示在文本框中,但这并不理想。我希望每个手柄都有一个单独的工具提示,分别显示 2 个值,并在拖动手柄时跟随手柄。如果做不到这一点,我可以把时间放在滑动手柄本身上。
我的问题是 - 如何定位特定句柄?它们由 jQuery 动态创建,并且仅由类定义,因此我不知道如何将 div 链接到特定句柄。
我在这里进行了搜索,发现了一些类似的问题,但没有真正回答这个问题。
另外,我不想使用插件。我知道存在一两个,但由于这种情况只发生在网站上的一个地方,我宁愿不必包含一个应该相当简单的文件(即使它打败了我:P)
I'm using a jQuery Range slider to let users select a time range in a day (i.e. 10:00 - 18:00).
At the moment it's all working fine and I have the output being displayed in a text box but this isn't ideal. I would prefer to have an individual tooltip for each handle that display the 2 values seperately and that follow the handle when you drag it. Failing that I could put the time in the slide handle itself.
My problem is - how do I target an specific handle? They dynamically created by jQuery and are defined only by classes so I don't know how I'd go about linking a div to a specific handle.
I had a search on here and found some similar questions but nothing that really answered this.
Also, I don't want to use a plugin. I know one or two exist but as this is only happening on one place on the site I'd rather not have to include a file for something that should be fairly simple (even if it has beaten me :P)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这有点旧,但我认为其他人可能会找到我感兴趣的解决方案(或者至少告诉我为什么它是垃圾)。
我基本上使用 JQuery 在用于滑块手柄的
a
元素内插入一个span
元素。每次使用滑块的change
事件移动手柄时,span
的内容都会更新。跨度本身使用 css 进行样式设置,因此仅当将鼠标悬停在手柄上并且略高于手柄本身时才会显示。所以它看起来像这样:所以,我的滑块被添加到带有
slider- 的所有元素中range
类如下:然后 css 如下所示:
就这样!享受
I know this is a bit old, but i think other people might find my solution of interest (or tell me why its rubbish at least).
I basically used JQuery to insert a
span
element inside thea
element that is used for the handle on the slider. The content of thespan
is then updated every time the handle is moved using the slider'schange
event. The span itself is styled using css so that it only shows up when hovering over the handle and is slightly above the handle itself. so it looks something like this:so, my sliders are added to all elements with the
slider-range
class like this:and then the css looks like this:
And thats all! enjoy
如果您只需要独立访问每个值,您可以附加
slide
函数来单独更新每个目标。此外,如果您希望能够分别更改这 2 个目标中每个目标的滑块,则可以使用values
方法轻松实现。编辑
我想我有点误解了你的问题。您可以使用一些选择器获取处理程序及其位置,例如:
下面是一个示例,说明如何使用该信息在拖动时在这些项目上显示工具提示。
示例: http://jsfiddle.net/niklasvh/vW7vy/
If you just need to access each value independently, you can attach the
slide
function to update each target seperately. Additionally, if you want to be able to change the slider from each of those 2 targets seperately, that works just as easily with thevalues
method.EDIT
Guess I misunderstood your question a bit. You can get the handlers and their positions with some selectors, such as:
Below is an example how you could use that information to display tooltips over those items when dragged.
Example: http://jsfiddle.net/niklasvh/vW7vy/
很好的努力,但效果并不完美。当您第一次将鼠标悬停在手柄上时。它不显示默认值。尝试使用相同的 CSS 样式。
Nice efforts but it dsn't work perfect. When you mouse hover the handle for first time. It dsnt show default values. Try this one with same CSS style.