【问题标题】:Jquery Range slider with tooltip带有工具提示的 Jquery Range 滑块
【发布时间】:2013-06-27 09:37:28
【问题描述】:

我正在使用带有范围滑块(滑块上有 2 个手柄)的 Jquery Ui 来过滤最小值和最大值。但是,任何想法如何为两个手柄添加工具提示,因为滑块本身不支持带有滑块的工具提示。

【问题讨论】:

标签: javascript jquery


【解决方案1】:

.ui-slider-handle 类在用作范围时有两个项目。因此,您必须正确使用 .first().last() 方法才能获得最小和最大范围处理程序。

这里是jsFiddle example

这是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();
    });

【讨论】:

    【解决方案2】:

    加载滑块后,您可以简单地在手柄上创建一个工具提示小部件

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

    【讨论】:

    • 已加载?你的意思是在 jquery ui 滑块初始化之后?
    • 加载和初始化是一样的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 2011-03-19
    相关资源
    最近更新 更多