Created
May 5, 2015 18:18
-
-
Save tomgp/cf66859111294eca384e to your computer and use it in GitHub Desktop.
do two DOM elements overlap?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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