tags:

views:

42

answers:

2

Hello,

I am wondering if it would be possible to attach a tooltip to the slider handle? My current slider function is:

            $('#slider').slider({
                max: 18,
                animate: 'slow',
                orientation: 'vertical',
                slide: function(e,ui) {
                    $('#storage').html(storage[ui.value-1]);
                    $('#ram').html(ram[ui.value-1]);
                    $('#bandwidth').html(bandwidth[ui.value-1]);
                    $('#cpu').html(cpu[ui.value-1]);
                    $('#price').html(price[ui.value-1]);
                }
            });

I want to take this and apply a tooltip to follow the handle. Would it be recommanded to somehow determine the position and dynamically update the tooltip position based on slider position?

A: 

Actually using the title attribute is the easier way ( belugabob idea)

$(function() {


  $("#slider").slider()
                .find(".ui-slider-handle")
                .attr("title", "Slide Me")

});

However if you want full control use this sample

Preview: http://jsbin.com/eluqi3

$(function() {

  var $slideMe = $("<div/>")
                    .css({ position : 'absolute' , top : 10, left : 0 })
                    .text("Slide Me!")
                    .hide()


  $("#slider").slider()
                .find(".ui-slider-handle")
                .append($slideMe)
                .hover(function()
                        { $slideMe.show()}, 
                       function()
                        { $slideMe.hide()}
                )

});
Ghommey
While I like your solution, I'm not convinced that the tooltip should be visible for the entire duration of the sliding action. By using a native browser tooltip, it will only appear for short while after the mouse enter the slider handle. All a matter of taste, I suppose.
belugabob
Guess you are right - it also simplifies the code ;)
Ghommey
my goal was to integrate some sort of nice css tooltip. Is this possible? Or only using the title attribute?
Steven
@Steven see my edited answer
Ghommey
+1  A: 

Just about any HTML element can be assigned a tooltip by giving it a 'title' attribute with the requred text being the value of the attribute.

In the case of your slider, can you reliably locate the HTML element used to draw the handle of the slider? If so, simply add a title attribute and you should be in business.

EDIT: Just as a general point, judicious use of the title attribute can make your pages tidier - by adding information that is context sensitive you don't take up screen real estate until it is actually required, and help out those who are unfamiliar with the UI of your site.

belugabob
I'm just trying to imagine what a tooltip in a slide handle would look like and I can't see it adding to the user's experience in a meaningful way. It might actually be detrimental, especially if it inadvertently covers the current value of the slider.
Rob Allen
True, and that is the advantage of your technique - there is more control over the position of the tooltip. My main concern is that the purpose of the tooltip is to prompt the inexperienced user and inform them of the use of the slider handle. Once they've started sliding, the tooltip is redundant.
belugabob