jQuery UI Slider: move the value along (with) the handle

前端 未结 6 1398
谎友^
谎友^ 2020-12-25 08:31

I used the jQuery UI slider component in my page to set a range of prices. I can also use their ui.values[] to set and show the new values in other divs.

6条回答
  •  悲&欢浪女
    2020-12-25 08:59

    You may use the .position utility function from jQuery UI to position the labels:

    $("#slider").slider({
        ...
        slide: function(event, ui) {
            var delay = function() {
                var handleIndex = $(ui.handle).data('index.uiSliderHandle');
                var label = handleIndex == 0 ? '#min' : '#max';
                $(label).html('$' + ui.value).position({
                    my: 'center top',
                    at: 'center bottom',
                    of: ui.handle,
                    offset: "0, 10"
                });
            };
    
            // wait for the ui.handle to set its position
            setTimeout(delay, 5);
        }
    });
    

    See it action: http://jsfiddle.net/william/RSkpH/1/.

提交回复
热议问题