简体   繁体   English

带工具提示的Jquery Range滑块

[英]Jquery Range slider with tooltip

I am using Jquery Ui with range slider (2 handles on sliders) to filter minimum and maximum values. 我正在使用带有范围滑块的Jquery Ui(滑块上的2个手柄)来过滤最小值和最大值。 However, any idea how to add tooltip for both handle, since the slider itself does not support tooltip with slider. 但是,任何想法如何为两个句柄添加工具提示,因为滑块本身不支持带滑块的工具提示。

.ui-slider-handle class has two items when used as a range. .ui-slider-handle类在用作范围时有两个项目。 Therefore you must use .first() and .last() methods properly in order to get min and max range handlers. 因此,必须正确使用.last() .first().last()方法才能获得最小和最大范围处理程序。

Here is the jsFiddle example . 这是jsFiddle的例子

This is the modified version of the answer of this question : 这是这个问题答案的修改版本:

    var tooltipmin = $('<div id="tooltip" />').css({
    position: 'absolute',
    top: -25,
    left: -10
}).hide();
var tooltipmax = $('<div id="tooltip" />').css({
    position: 'absolute',
    top: -25,
    left: -10
}).hide();
var slideritem = $("#slider").slider({
    values: [350, 500],
    min: 0,
    max: 1000,
    step: 50,
    range: true,
    slide: function(event, ui) {
        tooltipmin.text(ui.values[0]);
        tooltipmax.text(ui.values[1]);
    },
    change: function(event, ui) {
        tooltipmin.text(ui.values[0]);
        tooltipmax.text(ui.values[1]);
    }
});
slideritem
    .find(".ui-slider-handle")
    .first()
    .append(tooltipmin)
    .hover(function() {
        tooltipmin.show();
        tooltipmax.show();
    }, function() {
        tooltipmin.hide();
        tooltipmax.hide();
    });
slideritem
    .find(".ui-slider-handle")
    .last()
    .append(tooltipmax)
    .hover(function() {
        tooltipmin.show();
        tooltipmax.show();
    }, function() {
        tooltipmin.hide();
        tooltipmax.hide();
    });

加载滑块后,您只需在句柄上创建工具提示小部件

$('.ui-slider-handle').tooltip();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM