当我使用jquery ui删除元素时,获取我已经悬停的元素

时间:2015-01-23 12:49:01

标签: jquery jquery-ui

如何在放下被拖动的元素时获取我悬停的元素?

容器中的所有元素都有共同的.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?


        }
    });

1 个答案:

答案 0 :(得分:0)

试试这个: 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.
        }
    });
});

希望这有帮助。