intersect-rect
v1.0.0
Published
Check if two DOM elements intersect
Downloads
504
Maintainers
Readme
Intersect-rect
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!');
}