Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI: smooth slider with one snap (to default value)?

I'd like to make a slider that snaps to the center while retaining smooth action elsewhere. Something like a jQuery version of a real-life speaker balance slider. Is it possible?

Or should I just create my own slider with a draggable object, constricted to one axis with containing it frame, snapping to another object (or grid) positioned in the center of the frame?

Edit: I simply need a slider that allows values e.g. from -10 to -1, 0, and 1 to 10 (between -1 and 1 snap to 0) with step: 0.1

like image 798
Mike Avatar asked Nov 05 '22 03:11

Mike


1 Answers

You should be able to use the jQuery slider, but restrict its motion with the slide event:

jSlider.slider({
    // other options...
    slide: function (event, ui) {
        if (ui.value > -1 && ui.value < 1 && ui.value != 0) {
            // force it to 0 between -1 and 1.
            jSlider.slider('value', 0); 
            return false;
        }
        return true;
    }
});
like image 105
kevingessner Avatar answered Nov 14 '22 23:11

kevingessner