简体   繁体   中英

Make jQuery UI Slider clickable not draggable

I'm using jQuery UI 1.10.3. I'm looking to make an instance of the slider widget non-draggable. I want the user to be able to click to values along the slider only.

I have tried eventDefault on the slider's start method.. That didn't work (unresponsive slider). http://jsfiddle.net/3hTUz/

$("#slider").slider({
            value:100,
            min: 0,
            max: 500,
            step: 50
}).on({
    slide: function(e,ui) {
        $(this).data('v', ui.value);
        e.preventDefault();
    },
    mousedown: function() {
        var that = this;
        setTimeout(function() {
            var v = $(that).data('v');
            $(that).slider('value', v);
        },2);
    }
});

$( "#slider-value" ).html(  $('#slider').slider('value') );

FIDDLE

Just add draggable: false to your code like this

    $("#slider").slider(
{
            value:100,
            min: 0,
            max: 500,
            step: 50,
    draggable: false,
            slide: function( event, ui ) {
                $( "#slider-value" ).html( ui.value );
            },
            start: function( event, ui ) {
                //event.preventDefault();
            },
}
);

$( "#slider-value" ).html(  $('#slider').slider('value') );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM