[英]How do I use JQuery to iterate a form from the bottom to the top, most nested element first without knowing the id of the deepest element beforehand?
[英]How do I get the top most element at a given location with jQuery?
我有一個可拖動對象,在停止事件上,如果它沒有拖動到其他任何對象上,我想移到某個邊界。 問題:在可拖動處理程序的stop事件之后,發生了droppable處理的drop事件。 可拖動對象的停止處理程序提供了可拖動對象被拖動到的位置,但是我不知道如何確定該位置上的元素。 有任何想法嗎?
您可能只需要遍歷可放置元素並檢查其偏移位置即可。 結合每個元素的寬度/高度,您可以計算觸發stop事件時可拖動對象在哪個元素上。 這樣的事情(未經測試,在我的頭頂上)。
function stopCallback (x, y) {
var $droppables = $(".droppable"),
containedDraggableAtStop = function($item, left, top) {
var itemL = $item.offset().left,
itemT = $item.offset().top,
itemR = itemL + $item.width,
itemB = itemT + $item.height;
if (top > itemT && top < itemB && left > itemL && left < itemR) {
return true;
}
return false;
},
numDroppables = $droppables.length,
i;
// x, y are the coords passed from the stop function
for (i = 0; i < numDroppables; i++) {
if (containedDraggableAtStop($droppables.eq(i), x, y)) {
return $droppables.eq(i);
}
}
return -1;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.