我想知道某个节点是否与此架构相交的另一个节点:
答案 0 :(得分:0)
使用DOM属性top
和left
属性来确定它们与clientWidth
和clientHeight
这个小提琴检查重叠(假设你移动两个方框):http://jsfiddle.net/maniator/JnTaq/
代码:
$('.drag').draggable({
stop: function(event, ui) {
var others = $('.drag').not(this),
_self = this,
length = $(_self).width();
others.each(function(i, item) {
var this_left = parseInt(item.style.left) - length,
this_top = parseInt(item.style.top) - length;
if (ui.position.left > this_left && ui.position.top > this_top) {
var left = Math.abs(ui.position.left - this_left),
top = Math.abs(ui.position.top - this_top);
if (left <= (length*2) && top <= (length*2)) {
alert('overlap');
}
}
});
}
});