Skip to content

Instantly share code, notes, and snippets.

@Drumstix42
Last active May 30, 2019 00:59
Show Gist options
  • Select an option

  • Save Drumstix42/1263feaa25d0e8af642e0c77df897b54 to your computer and use it in GitHub Desktop.

Select an option

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.
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