jquery slider with value above it which travels with the slider

前端 未结 3 848
北荒
北荒 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条回答
  •  无人共我
    2021-02-04 16:40

    You can do something like this to build what you want, I am using event.pageX

    var newLeft = 100;
    $('#move').text(100).css('margin-left',115);
    $("#slider").slider(
    {
                value:100,
                min: 0,
                max: 500,
                step: 50,
                slide: function( event, ui ) {
                    $( "#slider-value" ).html( ui.value );
                    var  pos = (event.pageX > newLeft)? event.pageX + 8 
                                                      : event.pageX - 42;
                    newLeft = event.pageX;                
                    $('#move').text(ui.value).css('margin-left',pos);
                }
    }
    );
    

    Demo: http://jsfiddle.net/joycse06/Cw6u8/1/

提交回复
热议问题