1.0.0 • Published 7 years ago

intersect-rect v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

Intersect-rect

Code Climate Test Coverage

Intersect-rect is a tiny module to check if two DOM elements intersect (overlap).

Install

Intersect-rect can be installed using npm:

npm install --save intersect-rect

Loading intersect-rect using common JS:

var intersectRect = require('intersect-rect');

AMD / Browser

Intersect-rect also works out of the box in the browser or with AMD module loaders.

Example

var intersectRect = require('intersect-rect');

var elementA = document.getElementById('elementA');
var elementB = document.getElementById('elementB');

var rectA = elementA.getBoundingClientRect();
var rectB = elementB.getBoundingClientRect();

if (intersectRect(rectA, rectB)) {
  console.log('elementA and elementB overlap!');
} else {
  console.log('elementA and elementB do not overlap!');
}