当我使用 jquery ui 放置一个元素时获取我悬停的元素

Get the element I have hovered when I drop an element with jquery 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?


        }
    });

试试这个: http://jsfiddle.net/lotusgodkk/GCu2D/528/

JS:

$(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.
        }
    });
});

希望对您有所帮助。