-1

I want to know if a node intersects another node like this schema: schema

Flexo
  • 87,323
  • 22
  • 191
  • 272
MyBoon
  • 1,290
  • 1
  • 10
  • 18
  • possible duplicate of [Efficiently Detect When Sibling Elements Overlap](http://stackoverflow.com/questions/1560926/efficiently-detect-when-sibling-elements-overlap) – Abe Miessler Dec 19 '11 at 22:20
  • Related, possible duplicate: http://stackoverflow.com/questions/5720837/how-to-detect-elements-overlapping-overlaying-using-javascript – Rob Hruska Dec 19 '11 at 22:22

1 Answers1

0

Use the DOM attributes top and left attributes to figure out where they are along with clientWidth and clientHeight

This fiddle checks for overlaps (assuming you move both boxes): http://jsfiddle.net/maniator/JnTaq/

Code:

$('.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');
                }
            }
        });
    }
});
Naftali
  • 144,921
  • 39
  • 244
  • 303