jquery slider with value above it which travels with the slider

前端 未结 3 850
北荒
北荒 2021-02-04 15:42

I\'ve made a slider with query/slider and styled it with css. ( http://jsfiddle.net/9qwmX/ )

I succeeded to put the selected value into a div container; but now I want t

3条回答
  •  旧时难觅i
    2021-02-04 16:15

    You can just attach a tooltip-like div that you can append to the handle so it moves along with it. You just have to position it with CSS, like so:

    JS

    var initialValue = 2012; // initial slider value
    var sliderTooltip = function(event, ui) {
        var curValue = ui.value || initialValue; // current value (when sliding) or initial value (at start)
        var tooltip = '
    ' + curValue + '
    '; $('.ui-slider-handle').html(tooltip); //attach tooltip to the slider handle } $("#slider").slider({ value: initialValue, min: 1955, max: 2015, step: 1, create: sliderTooltip, slide: sliderTooltip });

    CSS tooltip borrowed from the twitter bootstrap framework

    .tooltip {
        position: absolute;
        z-index: 1020;
        display: block;
        padding: 5px;
        font-size: 11px;
        visibility: visible;
        margin-top: -2px;
        bottom:120%;
        margin-left: -2em;
    }
    
    .tooltip .tooltip-arrow {
        bottom: 0;
        left: 50%;
        margin-left: -5px;
        border-top: 5px solid #000000;
        border-right: 5px solid transparent;
        border-left: 5px solid transparent;
        position: absolute;
        width: 0;
        height: 0;
    }
    
    .tooltip-inner {
        max-width: 200px;
        padding: 3px 8px;
        color: #ffffff;
        text-align: center;
        text-decoration: none;
        background-color: #000000;
        -webkit-border-radius: 4px;
           -moz-border-radius: 4px;
                border-radius: 4px;
    }
    

    Demo: http://jsfiddle.net/9qwmX/2/

提交回复
热议问题