Skip to content

Instantly share code, notes, and snippets.

@tomgp
Created May 5, 2015 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomgp/cf66859111294eca384e to your computer and use it in GitHub Desktop.
Save tomgp/cf66859111294eca384e to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment