Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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

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_Jquery Ui - Fatal编程技术网

获取在jquery ui中放置元素时悬停的元素

获取在jquery ui中放置元素时悬停的元素,jquery,jquery-ui,Jquery,Jquery Ui,如何获取在拖放元素时悬停的元素 容器中的所有元素都有一个共同的class.droppableYElement $("#container").droppable({ accept: ".droppableXElement", activeClass: "ui-state-hover", hoverClass: "ui-state-active", drop: function (event, ui) {

如何获取在拖放元素时悬停的元素

容器中的所有元素都有一个共同的class.droppableYElement

 $("#container").droppable({
        accept: ".droppableXElement",
        activeClass: "ui-state-hover",
        hoverClass: "ui-state-active",
        drop: function (event, ui) {

            alert("I am dropped");

  // How can I get the element which I hovered at the moment of dropping the dragged element?


        }
    });
试试这个:

JS:


希望这能有所帮助。

$drop函数中的此选项将为您获取悬停的元素或拖放的元素。尝试itI当我悬停并拖放被拖动的元素时,我总是获取被拖放区域的父容器,而不是该区域内的div。我不想在可拖动设备掉落的区域进行移动。我想要当我放下元素时鼠标指针在上面的元素。你能创建一个相关HTML吗?检查你的事件中的currentTarget?event.currentTarget jquery将$包装在您的drop回调中,并查看这是否是您要查找的对象?event.currentTarget看起来像我的窗口对象?没有什么有用的,或者我看错了吗?此$event.currentTarget;没有帮助结果对象中没有任何有用的东西。哥们!你太棒了!你知道我已经想做什么了吗?我想到了一些不好的事情,比如:将mouser over事件订阅给itemContainer的所有子项,并在事件$this中写入一个globalVariable.lastHoveredElement,当我在drop函数中时,我只会从lastHoveredElement:P:D中获取值,不管怎样,这保存了您的experiments@K在你的演示中效果很好,但现在我将其实现到生产代码中我从points获得的元素不是div,而是整个footer.html???搞什么鬼!我迷路了…它在今天下午工作了,现在不再工作了,我恢复了所有的argh…甚至删除了缓存。我猜可能是因为div有svg文件,没有像透明颜色那样的背景。。。这给了我们将看到的页脚…@Elisa如果你能分享生产链接,那么我将更容易看到这个问题。
$(document).ready(function () {
    $("#itemContainer > div").each(function (index, element) {
        $(element).draggable();
    });

    $("#itemContainer").droppable({
        activeClass: "ui-state-hover",
        hoverClass: "ui-state-active",
        drop: function (event, ui) {
            var element = document.elementFromPoint(event.pageX, event.pageY);
//Get the coordinates of mouse and using these coordinates, find the element. 
            console.log(element); //Element which was hovered.
        }
    });
});