7

I'm trying to add control buttons on to the jQuery UI slider but can't get it to work.

Can anyone see what im doing wrong here:

$(function() {

    var gmin = 1;
    var gmax = 500;

    $( "#slider" ).slider({
        value:5,
        min: gmin,
        max: gmax,
        step: 1,
        slide: function( event, ui ) {
            $( "#donate_amount_label span" ).html( "£" + ui.value );
        }
    });

    $( "#donate_amount_label span" ).html( "£" + $( "#slider" ).slider( "value" ) );
    $( "#" ).val( $( "#slider" ).slider( "value" ) );

    $('#down').click(function() {

      var s = $("#slider");
      s.slider('value', s.slider('value') + s.slider( "step" ) );   

    });

});

The slider works fine and the values get updated but when you click the #down link nothing happens to the scrollbar. I would like it to move up one step when the #down link is clicked.

Thanks Pete

1 Answer 1

3

You should do:

var s =  $( "#slider" ).slider({
    value:5,
    min: gmin,
    max: gmax,
    step: 1,
    slide: function( event, ui ) {
        $( "#donate_amount_label span" ).html( "£" + ui.value );
    }
});

$('#down').click(function() {
  s.slider('value', s.slider('value') + s.slider( "option", "step" ) );   

});

the error was in getting the step. You must use

 s.slider( "option", "step" ) 

fiddle here http://jsfiddle.net/nrNX8/ (with a step at 1 it moves very slooooooowly)

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to modify it to keep scrolling if the mousebutton is held down?
It seems that in yours example slide event is not firing up using #down

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.