2011-12-19 76 views
-1

我想知道,如果一个节点相交,这样的架构中的另一个节点: schema如何知道一个节点是否与另一个节点相交?

+0

[兄弟元素重叠时高效检测]的可能重复(http://stackoverflow.com/questions/1560926/efficiently-detect-when-sibling-elements-overlap) – 2011-12-19 22:20:08

+0

相关,可能重复:http://stackoverflow.com /问题/ 5720837 /如何对检测元素重叠-使用重叠-JavaScript的 – 2011-12-19 22:22:28

回答

0

使用DOM属性topleft属性弄清楚它们与clientWidthclientHeight

这捣鼓重叠检查一起在那里(假设你移动这两个框):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'); 
       } 
      } 
     }); 
    } 
}); 
相关问题