0

I am looking for a guideline to check when div( using bootstrap grid or not ) elements are overlapping. So far, I have checked the position and mismatched tags using chrome developer tool.

1 Answers1

0

You are looking for collision detection. The following Javascript code shows how to detect overlapping HTML div tags. Please find more here: How to detect overlapping elements

function collision($div1, $div2) {
  var x1 = $div1.offset().left;
  var y1 = $div1.offset().top;
  var h1 = $div1.outerHeight(true);
  var w1 = $div1.outerWidth(true);
  var b1 = y1 + h1;
  var r1 = x1 + w1;
  var x2 = $div2.offset().left;
  var y2 = $div2.offset().top;
  var h2 = $div2.outerHeight(true);
  var w2 = $div2.outerWidth(true);
  var b2 = y2 + h2;
  var r2 = x2 + w2;

  if (b1 < y2 || y1 > b2 || r1 < x2 || x1 > r2) return false;
  return true;
}
Community
  • 1
  • 1
LoreV
  • 575
  • 5
  • 25