jquery ui slider,如果满足某些条件则停止滑动

时间:2010-10-15 00:59:03

标签: jquery-ui

使用jQuery UI Slider,我正在试图弄清楚如何使滑块在满足某些条件后停止工作。有任何想法吗?我认为在“开始”部分停止事件传播会起作用,但是......事实并非如此。所以我仍然无能为力,迷失方向。

<script type="text/javascript">
    $(document).ready(function () {
        var spendable = 1000;
        var spent = 0;

        function spend(quantity) {

            var remaining = spendable - quantity;
            $('#spendable').text(remaining);
        }

        $("#eq .slider").each(function () {
            var current = 0;
            $(this).slider({
                range: "min",
                step: 100,
                value: 0,
                min: 0,
                max: 500,
                animate: true,
                orientation: "horizontal",
                start: function (event, ui) {
                    if (spent < spendable)
                        return true;
                    event.stopPropagation();
                },
                slide: function (event, ui) {
                    // set the current value to whatever is selected.
                    current = ui.value;
                    $(this).parent('div:eq(0)').find('.spent').text(current);

                    var totalled = 0;
                    $("#eq .slider").each(function () {
                        totalled += parseInt($(this).parent('div:eq(0)').find('.spent').text());
                        spend(totalled);
                    });
                }
            });
        });

1 个答案:

答案 0 :(得分:7)

尝试:

.....

slide: function (event, ui) {
                    // set the current value to whatever is selected.
                    current = ui.value;
                    if(current > 300){
                       current = 300; //otherwise, it's stuck at 301
                       return false;
                     }

                   ....rest of your code