tomgp
5/5/2015 - 6:18 PM

do two DOM elements overlap?

do two DOM elements overlap?

function intersection(elementA, elementB){
  var a = elementA.getBoundingClientRect(),
    b = elementB.getBoundingClientRect();
  var overlap = (a.left <= b.right &&
    b.left <= a.right &&
    a.top <= b.bottom &&
    b.top <= a.bottom);
    return overlap;
}