jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery ui slider-尝试禁用单个句柄大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个ui范围滑块.我已经更改了脚本以添加其他范围和句柄.我试图禁用其中一个句柄,(显示整个部分总是将成为计算的一部分,因此不应该是可变的,但需要一个可见的段).

我在幻灯片中尝试过:
    if(ui.value == ui.values [3]&& ui.value> 98){
          关闭();

}
           if ( ui.value == ui.values[3] && ui.value < 98 ) {
         off();
    }

同时使用off()和return false,然后句柄本身被冻结,但它仍在计算值,就像它被移动一样.

所以,我试图禁用 – 我尝试过:
    $( ‘A.ui滑块把手’)当量(2).draggable(假); //这个以某种方式让我把它拖到整个页面

$(‘A.ui-slider-handle’).eq(2).attr(‘disabled’,’disabled’);
$( ‘A.ui滑块把手’)当量(2).prop( ‘禁用’);

但这些都不起作用.有什么建议?我是新手并输了.谢谢!

解决方法

@H_696_27@ 据我所知,jQuery UI滑块小部件无法禁用单个句柄.但是,如果您不介意扩展jQuery UI滑块小部件,则可以添加功能.

在下面的代码中,我在jQuery UI滑块小部件中扩展了_mouseCapture函数,以防止鼠标移动/选择具有ui-slider-handle-disabled类的句柄.它有点大,因为我必须复制现有的_mouseCapture函数添加几行.我用插词标记了我的插入内容.

您可以测试此代码here on jsfiddle.

// extend jQuery UI slider widget's _mouseCapture function to allow disabling handles
// _mouseCapture function copied from jQuery UI v1.10.3
$.widget("ui.slider",$.ui.slider,{
    _mouseCapture: function (event) {
        var position,normValue,distance,closestHandle,index,allowed,offset,mouSEOverHandle,that = this,o = this.options;

        if (o.disabled) {
            return false;
        }

        this.elementSize = {
            width: this.element.outerWidth(),height: this.element.outerHeight()
        };
        this.elementOffset = this.element.offset();

        position = {
            x: event.pageX,y: event.pageY
        };
        normValue = this._normValueFromMouse(position);
        distance = this._valueMax() - this._valueMin() + 1;
        this.handles.each(function (i) {
            // Added condition to skip closestHandle test if this handle is disabled.
            // This prevents disabled handles from being moved or SELEcted with the mouse.
            if (!$(this).hasClass("ui-slider-handle-disabled")) {
                var thisDistance = Math.abs(normValue - that.values(i));
                if ((distance > thisDistancE) || (distance === thisDistance && (i === that._lastChangedValue || that.values(i) === o.min))) {
                    distance = thisDistance;
                    closestHandle = $(this);
                    index = i;
                }
            }
        });

        // Added check to exit gracefully if,for some reason,all handles are disabled
        if(typeof closestHandle === 'undefined')
            return false;

        allowed = this._start(event,indeX);
        if (allowed === falsE) {
            return false;
        }
        this._mouseSliding = true;

        this._handleIndex = index;

        closestHandle.addClass("ui-state-active")
            .focus();

        offset = closestHandle.offset();
        // Added extra condition to check if the handle currently under the mouse cursor is disabled.
        // This ensures that if a disabled handle is clicked,the nearest handle will remain under the mouse cursor while dragged.
        mouSEOverHandle = !$(event.target).parents().addBACk().is(".ui-slider-handle") || $(event.target).parents().addBACk().is(".ui-slider-handle-disabled");
        this._clickOffset = mouSEOverHandle ? {
            left: 0,top: 0
        } : {
            left: event.pageX - offset.left - (closestHandle.width() / 2),top: event.pageY - offset.top - (closestHandle.height() / 2) - (parseInt(closestHandle.css("borderTopWidth"),10) || 0) - (parseInt(closestHandle.css("borderBottomWidth"),10) || 0) + (parseInt(closestHandle.css("marginTop"),10) || 0)
        };

        if (!this.handles.hasClass("ui-state-hover")) {
            this._slide(event,normvalue);
        }
        this._animateOff = true;
        return true;
    }
});

大佬总结

以上是大佬教程为你收集整理的jquery ui slider-尝试禁用单个句柄全部内容,希望文章能够帮你解决jquery ui slider-尝试禁用单个句柄所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。