如何在放下被拖动的元素时获取我悬停的元素?
容器中的所有元素都有共同的.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?
}
});
答案 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.
}
});
});
希望这有帮助。