Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery UI可通过选择性元素上的选择性鼠标按钮(同时从左到右)拖动_Javascript_Jquery_User Interface_Draggable_Right Click - Fatal编程技术网

Javascript jQuery UI可通过选择性元素上的选择性鼠标按钮(同时从左到右)拖动

Javascript jQuery UI可通过选择性元素上的选择性鼠标按钮(同时从左到右)拖动,javascript,jquery,user-interface,draggable,right-click,Javascript,Jquery,User Interface,Draggable,Right Click,我使用jqueryui来拖动div元素。当我用鼠标左键拖动时,有一个div,它是可拖动的。我也想用鼠标右键拖动它。所以我想用鼠标左键和右键拖动项目。但只有这个div元素,其他元素只能用鼠标左键拖动 我修改jQuery UI js文件,如下所示: $(document).ready(function () { //override jQuery UI draggable $.extend($.ui.draggable.prototype, { _mouseDown: function (

我使用jqueryui来拖动div元素。当我用鼠标左键拖动时,有一个div,它是可拖动的。我也想用鼠标右键拖动它。所以我想用鼠标左键和右键拖动项目。但只有这个div元素,其他元素只能用鼠标左键拖动

我修改jQuery UI js文件,如下所示:

$(document).ready(function () {
//override jQuery UI draggable
$.extend($.ui.draggable.prototype, {

    _mouseDown: function (event) {

        // we may have missed mouseup (out of window)
        (this._mouseStarted && this._mouseUp(event));

        this._mouseDownEvent = event;

        var that = this,
        btnIsLeft = (event.type === 'mousedown'),

            // event.target.nodeName works around a bug in IE 8 with
            // disabled inputs (#7620)
            elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
        if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
            return true;
        }

        this.mouseDelayMet = !this.options.delay;
        if (!this.mouseDelayMet) {
            this._mouseDelayTimer = setTimeout(function () {
                that.mouseDelayMet = true;
            }, this.options.delay);
        }

        if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
            this._mouseStarted = (this._mouseStart(event) !== false);
            if (!this._mouseStarted) {
                event.preventDefault();
                return true;
            }
        }

        // Click event may never have fired (Gecko & Opera)
        if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
            $.removeData(event.target, this.widgetName + ".preventClickEvent");
        }

        // these delegates are required to keep context
        this._mouseMoveDelegate = function (event) {
            return that._mouseMove(event);
        };
        this._mouseUpDelegate = function (event) {
            return that._mouseUp(event);
        };
        $(document)
            .bind("mousemove." + this.widgetName, this._mouseMoveDelegate)
            .bind("mouseup." + this.widgetName, this._mouseUpDelegate);

        event.preventDefault();

        mouseHandled = true;
        return true;
    }
  });
});
变化如下: btnIsLeft=(event.type=='mousedown'),

在这段代码中,我的特定div元素可以很好地工作,它也可以使用鼠标左键和右键,但是其他元素可以使用鼠标左键和右键拖动,这是我不想要的

我的div元素是这样的(我只想将其应用于左右拖动功能):

$('.mydiv_with_right_and_left_drag').draggable({
    scroll: false,
    delay: 0,
    distance: 0,                                        
    cursor: 'hand',                                     
    snap: false,                                        
    cursor: 'pointer',
    stack: '.mydiv_with_right_and_left_drag',
    containment: 'parent',                              
    opacity: 0.35,                                                                                                                  
});


这是可行的吗?谢谢。

请给出一个更详细的例子来详细说明,并准确描述您所采取的步骤,以及哪些没有按预期工作。这就是我喜欢的: