最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Stopping the jQuery UI slider from moving past a given value? - Stack Overflow

programmeradmin3浏览0评论

On my page I have several sliders. They all need the same scale, but some of them go to 150, and some go to 200. I would like to set the max of them all to 200, but prevent some of them from moving passed 150. They are different $().slider() calls, so I'm simply interested in how to set the max of a slider to 200, but not allow any movement past 150...

I would think that this kind of behavior would be built-in, but apparently not?

FYI: I am using range: "min" for these sliders.

EDIT

/

On my page I have several sliders. They all need the same scale, but some of them go to 150, and some go to 200. I would like to set the max of them all to 200, but prevent some of them from moving passed 150. They are different $().slider() calls, so I'm simply interested in how to set the max of a slider to 200, but not allow any movement past 150...

I would think that this kind of behavior would be built-in, but apparently not?

FYI: I am using range: "min" for these sliders.

EDIT

http://jsfiddle/D9nAx/1/

Share Improve this question edited Sep 14, 2012 at 18:56 Erik Funkenbusch 93.5k29 gold badges201 silver badges292 bronze badges asked Sep 14, 2012 at 18:08 S16S16 2,9959 gold badges43 silver badges64 bronze badges 3
  • 1 Please add the relevant HTML and/or scripts/css to your post so we can improve on top of what you have. In addition if you can create a fidde on jsFiddle that would also alow us to try out different solutions. – Nope Commented Sep 14, 2012 at 18:16
  • I'm sure you can use the slider events to control its behaviour. – Musa Commented Sep 14, 2012 at 18:20
  • link added: jsfiddle/D9nAx/1 – S16 Commented Sep 14, 2012 at 18:51
Add a ment  | 

2 Answers 2

Reset to default 7

use slide event:

$( "#slider-vertical" ).slider({
    orientation: "vertical",
    range: "min",
    min: 0,
    max: 200,
    value: 60,
    slide: function( event, ui ) {
        if(ui.value> 150)
            return false;
        $( "#amount" ).val( ui.value );
    }
});

fiddle : http://jsfiddle/dvz8E

$( "#slider-vertical" ).slider({
    orientation: "vertical",
    range: "min",
    min: 0,
    max: 200,
    value: 60,
    slide: slide
});
function slide(event, ui){
    var result = true;
    if (ui.value > 150){
        $(this).slider( "value" , 150 );
        result = false;
    }
    $( "#amount" ).val( $(this).slider( "value") );
    return result;
}

http://jsfiddle/D9nAx/2/

发布评论

评论列表(0)

  1. 暂无评论