Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
Jquery ui 可拖放事件:如何获取鼠标移动到的元素_Jquery Ui_Events_Drag And Drop - Fatal编程技术网

Jquery ui 可拖放事件:如何获取鼠标移动到的元素

Jquery ui 可拖放事件:如何获取鼠标移动到的元素,jquery-ui,events,drag-and-drop,Jquery Ui,Events,Drag And Drop,在可拖放事件期间,我需要鼠标光标移动到的元素。如果此元素不可拖放,则应执行默认行为 我尝试了以下方法: $(dropSelector).droppable({ over: function (event, ui) { ui.helper.css("cursor", "copy"); // Some code on drop enter here... },

在可拖放事件期间,我需要鼠标光标移动到的元素。如果此元素不可拖放,则应执行默认行为

我尝试了以下方法:

            $(dropSelector).droppable({
            over: function (event, ui) {
                ui.helper.css("cursor", "copy");
                // Some code on drop enter here...
            },
            out: function (event, ui) {
                // New element: mouse pointer might move to another droppable element...
                // How to obtain the element where the mouse moves to?
                if (/* next element is NOT droppable*/) {
                    ui.helper.css("cursor", "no-drop");
                    // Some code on drop out here...
                }
            },
            drop: function (event, ui) {
                // handle drop event
            }
        });

但是,我找不到一种方法来获取在
out
事件期间鼠标光标移动到的元素。。我尝试了
event.target
event.currentTarget
,但它们不是我要寻找的元素。

我使用了不同的解决方案。显然,下一个元素的
over
事件在旧元素的
out
事件之前触发。因此,我检查out目标是否是最后输入的元素

    var _target = null;
    $(dropSelector).droppable({
        over: function (event, ui) {
            _target = event.target;
            ui.helper.css("cursor", "copy");
            // Some code on drop enter here...
        },
        out: function (event, ui) {
            if (_target === event.target) {
                // No 'over' occurred for a new element
                ui.helper.css("cursor", "no-drop");
                // Some code on drop out here...
            }
            else {
               // Some code on drop out of old element

               // Perhaps some code on 'over' that has to be done after
               // drop out of old element
            }

        },
        drop: function (event, ui) {
            // handle drop event
        }
    });   
但是:我可以相信这样一个事实:在旧元素上发出
之前,在下一个元素上发出
over