Last active
May 30, 2019 00:59
-
-
Save Drumstix42/1263feaa25d0e8af642e0c77df897b54 to your computer and use it in GitHub Desktop.
Check if two elements are overlapping one another, based on their position relative to the viewport.
This file contains hidden or 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 isElementOverlapping(elem1, elem2) { | |
| var rect1 = elem1.getBoundingClientRect(); | |
| var rect2 = elem2.getBoundingClientRect(); | |
| return !( | |
| rect1.right < rect2.left || | |
| rect1.left > rect2.right || | |
| rect1.bottom < rect2.top || | |
| rect1.top > rect2.bottom | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment